|
|
|
|
@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.biutag.supervision.constants.AppConstants; |
|
|
|
|
import com.biutag.supervision.mapper.SupPoliceMapper; |
|
|
|
|
import com.biutag.supervision.pojo.Result; |
|
|
|
|
import com.biutag.supervision.pojo.domain.PoliceAuth; |
|
|
|
|
import com.biutag.supervision.pojo.dto.PoliceDto; |
|
|
|
|
@ -24,12 +25,14 @@ import com.biutag.supervision.pojo.entity.*;
|
|
|
|
|
import com.biutag.supervision.pojo.model.PoliceModel; |
|
|
|
|
import com.biutag.supervision.pojo.param.PoliceQueryParam; |
|
|
|
|
import com.biutag.supervision.service.*; |
|
|
|
|
import jakarta.annotation.Resource; |
|
|
|
|
import jakarta.validation.ConstraintViolation; |
|
|
|
|
import jakarta.validation.Valid; |
|
|
|
|
import jakarta.validation.Validator; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import org.apache.xmlbeans.UserType; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
@ -55,6 +58,9 @@ public class PoliceController {
|
|
|
|
|
|
|
|
|
|
private final Validator validator; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private SupPoliceMapper supPoliceMapper; |
|
|
|
|
|
|
|
|
|
@GetMapping |
|
|
|
|
public Result<Page<PoliceModel>> list(PoliceQueryParam param) { |
|
|
|
|
return Result.success(policeService.page(param)); |
|
|
|
|
@ -73,6 +79,7 @@ public class PoliceController {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@PostMapping |
|
|
|
|
@Transactional |
|
|
|
|
public Result<Boolean> add(@Valid @RequestBody PoliceDto policeDto) { |
|
|
|
|
SupPolice policeByEmpNo = policeService.getOne(new LambdaQueryWrapper<SupPolice>().eq(SupPolice::getEmpNo, policeDto.getEmpNo())); |
|
|
|
|
if (Objects.nonNull(policeByEmpNo)) { |
|
|
|
|
@ -84,20 +91,28 @@ public class PoliceController {
|
|
|
|
|
SupDepart depart = departService.getById(one.getOrgId()); |
|
|
|
|
throw new RuntimeException(String.format("该人员[%s]已存在于“%s”单位中,请联系二级机构或市局管理员以进行人员调整。", policeDto.getIdCode(), depart.getName())); |
|
|
|
|
} |
|
|
|
|
SupPolice police = new SupPolice(); |
|
|
|
|
BeanUtils.copyProperties(policeDto, police); |
|
|
|
|
police.setId(IdUtil.getSnowflakeNextIdStr()); |
|
|
|
|
police.setUpdatedAt(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMAT)); |
|
|
|
|
police.setCreatedAt(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMAT)); |
|
|
|
|
policeService.save(police); |
|
|
|
|
if (policeDto.getCreateUserFlag() && !userService.exists(new LambdaQueryWrapper<BaseUser>().eq(BaseUser::getUserName, police.getIdCode()))) { |
|
|
|
|
UserDto userDto = new UserDto(); |
|
|
|
|
userDto.setUserName(police.getIdCode()); |
|
|
|
|
userDto.setNickName(police.getName()); |
|
|
|
|
userDto.setPassword(policeDto.getPassword()); |
|
|
|
|
userDto.setUserType("normal"); |
|
|
|
|
userDto.setRoleIds(new ArrayList<>()); |
|
|
|
|
baseUserService.save(userDto); |
|
|
|
|
SupPolice delPolice= supPoliceMapper.selectByIdCodeAndDel(policeDto.getIdCode(), AppConstants.DEL); |
|
|
|
|
if (Objects.nonNull(delPolice)){ |
|
|
|
|
delPolice.setOrgId(policeDto.getOrgId()); |
|
|
|
|
delPolice.setDel(AppConstants.UN_DEL); |
|
|
|
|
delPolice.setDelReason(""); |
|
|
|
|
supPoliceMapper.updateIgnoreLogicDeleteById(delPolice); |
|
|
|
|
}else { |
|
|
|
|
SupPolice police = new SupPolice(); |
|
|
|
|
BeanUtils.copyProperties(policeDto, police); |
|
|
|
|
police.setId(IdUtil.getSnowflakeNextIdStr()); |
|
|
|
|
police.setUpdatedAt(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMAT)); |
|
|
|
|
police.setCreatedAt(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_FORMAT)); |
|
|
|
|
policeService.save(police); |
|
|
|
|
if (policeDto.getCreateUserFlag() && !userService.exists(new LambdaQueryWrapper<BaseUser>().eq(BaseUser::getUserName, police.getIdCode()))) { |
|
|
|
|
UserDto userDto = new UserDto(); |
|
|
|
|
userDto.setUserName(police.getIdCode()); |
|
|
|
|
userDto.setNickName(police.getName()); |
|
|
|
|
userDto.setPassword(policeDto.getPassword()); |
|
|
|
|
userDto.setUserType("normal"); |
|
|
|
|
userDto.setRoleIds(new ArrayList<>()); |
|
|
|
|
baseUserService.save(userDto); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return Result.success(); |
|
|
|
|
} |
|
|
|
|
|