package com.estate.expert.admin.controller.admin; import com.estate.expert.admin.domain.business.screenaccount.*; import com.estate.expert.admin.domain.user.User; import com.estate.expert.admin.domain.common.request.BatchReq; import com.estate.expert.admin.domain.common.request.PageReq; import com.estate.expert.admin.service.ScreenAccountService; import com.estate.expert.admin.utils.MD5Utils; import com.estate.expert.common.domain.Session; import com.estate.expert.common.rpc.Result; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.time.LocalDateTime; @Slf4j @CrossOrigin @Api(tags = "管理后台/大屏账号") @RequestMapping("/admin/screen-account") @RestController @Validated public class ScreenAccountController { @Resource private ScreenAccountService screenAccountService; @ApiOperation(value = "大屏账号列表") @PostMapping("/list") public Result list(@ApiParam(value = "账号名称") @RequestParam(value = "name", required = false) String name, @ApiParam(value = "关键词") @RequestParam(value = "keyword", required = false) String keyword, @ApiParam(value = "账号类型") @RequestParam(value = "type", required = false) Integer type, @Validated @RequestBody PageReq pageReq) { return Result.success(screenAccountService.list(name, keyword, type,pageReq)); } @ApiOperation(value = "大屏账号详情") @GetMapping("/detail/{id}") public Result detail(@PathVariable Integer id) { ScreenAccount screenAccount = screenAccountService.getById(id); if (screenAccount == null) { return Result.error("账号不存在"); } ScreenAccountDto vo = new ScreenAccountDto(); BeanUtils.copyProperties(screenAccount, vo); return Result.success(vo); } @ApiOperation(value = "新增大屏账号") @PostMapping("/add") public Result add(@Validated @RequestBody ScreenAccountAddDto dto) { if (screenAccountService.existsByAccount(dto.getAccount())) { return Result.error("账号已存在"); } ScreenAccount screenAccount = new ScreenAccount(); BeanUtils.copyProperties(dto, screenAccount); screenAccount.setPassword(MD5Utils.encrypt(dto.getPassword())); return Result.success(screenAccountService.save(screenAccount)); } @ApiOperation(value = "编辑大屏账号") @PostMapping("/edit") public Result edit(@Validated @RequestBody ScreenAccountEditDto dto) { ScreenAccount screenAccount = new ScreenAccount(); BeanUtils.copyProperties(dto, screenAccount); if (screenAccountService.existsByAccountAndIdNot(dto.getAccount(), dto.getId())) { return Result.error("账号已存在"); } if (dto.getPassword() != null && !dto.getPassword().isEmpty()) { screenAccount.setPassword(MD5Utils.encrypt(dto.getPassword())); } return Result.success(screenAccountService.updateById(screenAccount)); } @ApiOperation(value = "删除大屏账号") @DeleteMapping("/delete/{id}") public Result delete(@PathVariable Integer id) { ScreenAccount screenAccount = screenAccountService.getById(id); if (screenAccount == null) { return Result.error("账号不存在"); } screenAccount.setDeleted( true); screenAccount.setUpdateTime(LocalDateTime.now()); return Result.success(screenAccountService.updateById(screenAccount)); } @ApiOperation(value = "启用禁用账号") @PostMapping("/enable/{id}") public Result enable(@PathVariable Integer id) { ScreenAccount screenAccount = screenAccountService.getById(id); if (screenAccount == null) { return Result.error("账号不存在"); } screenAccount.setState(screenAccount.getState() == 1 ? 2 : 1); screenAccount.setUpdateTime(LocalDateTime.now()); return Result.success(screenAccountService.updateById(screenAccount)); } @ApiOperation(value = "重置密码") @PostMapping("/resetPassword") public Result resetPassword(@Validated @RequestBody ScreenAccountEditPasswordDto dto) { ScreenAccount screenAccount = new ScreenAccount(); BeanUtils.copyProperties(dto, screenAccount); screenAccount.setPassword(MD5Utils.encrypt(dto.getPassword())); return Result.success(screenAccountService.updateById(screenAccount)); } }