| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.project.common.annotation.DataScope; |
| | | import com.project.common.constant.CheckLevelCodeConstants; |
| | | import com.project.common.core.domain.entity.SysRole; |
| | | import com.project.common.core.domain.entity.SysUser; |
| | | import com.project.common.exception.base.BaseException; |
| | | import com.project.common.enums.OrderPre; |
| | | import com.project.common.sms.YPSmsApi; |
| | | import com.project.common.utils.SecurityUtils; |
| | | import com.project.common.utils.StringUtils; |
| | | import com.project.common.vo.KeyVal; |
| | | import com.project.enforce.domain.EnforceOrder; |
| | | import com.project.enforce.domain.EnforcePeer; |
| | | import com.project.enforce.domain.bo.editBo.EnforceOrderBo; |
| | | import com.project.enforce.domain.bo.queryBo.EnforceOrderQueryBo; |
| | | import com.project.enforce.domain.vo.EnforceOrderVo; |
| | | import com.project.enforce.mapper.EnforceOrderMapper; |
| | | import com.project.enforce.service.IEnforceOrderService; |
| | | import com.project.enforce.service.IEnforcePeerService; |
| | | import com.project.system.service.ISysDeptService; |
| | | import com.project.system.service.ISysOrderNoService; |
| | | import com.project.system.service.ISysUserService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 执法单Service业务层处理 |
| | |
| | | @RequiredArgsConstructor(onConstructor_ = @Autowired) |
| | | public class EnforceOrderServiceImpl extends ServiceImpl<EnforceOrderMapper, EnforceOrder> implements IEnforceOrderService { |
| | | |
| | | private final ISysUserService userService; |
| | | private final ISysDeptService deptService; |
| | | private final EnforceOrderMapper orderMapper; |
| | | |
| | | private final ISysOrderNoService orderNoService; |
| | | private final IEnforcePeerService peerService; |
| | | |
| | | @Override//列表查询 |
| | | @DataScope(deptAlias = "apply_dept_id", userAlias = "apply_user_id") |
| | |
| | | public List<EnforceOrderVo> queryCheckList(EnforceOrderQueryBo bo) |
| | | { |
| | | SysUser loginUser = SecurityUtils.getLoginUser().getUser(); |
| | | if (bo.getIsCheckQuery()!=null && bo.getIsCheckQuery()==1){ |
| | | List<String> roleKeys = loginUser.getRoles().stream().map(SysRole::getRoleKey).collect(Collectors.toList()); |
| | | if (roleKeys.contains(CheckLevelCodeConstants.CHECK_LEVEL_ONE) && roleKeys.contains(CheckLevelCodeConstants.CHECK_LEVEL_TWO)){ |
| | | bo.setCheckLevel(null); |
| | | } else if (roleKeys.contains(CheckLevelCodeConstants.CHECK_LEVEL_ONE)){ |
| | | bo.setCheckLevel(0); |
| | | } else if (roleKeys.contains(CheckLevelCodeConstants.CHECK_LEVEL_TWO)) { |
| | | bo.setCheckLevel(1); |
| | | } else { |
| | | throw new BaseException("您没有审批权限,请重试!"); |
| | | } |
| | | } |
| | | |
| | | bo.setCheckDeptId(deptService.getCheckDeptIdByLoginDeptId(loginUser.getDeptId())); |
| | | bo.setCheckIds(loginUser.getPhonenumber()); |
| | | bo.setApplyDeptIds(deptService.getApplyDeptIdsByLoginUserId(loginUser.getUserId())); |
| | | |
| | | return this.baseMapper.selectCheckList(bo); |
| | | } |
| | | |
| | |
| | | public Boolean insertByBo(EnforceOrderBo bo) |
| | | { |
| | | EnforceOrder add = Convert.convert(EnforceOrder.class, bo); |
| | | add.setCheckLevel(0); |
| | | validEntityBeforeSave(add); |
| | | return this.save(add); |
| | | List<String> phones = getCheckPhones(add.getCheckLevel(), add.getApplyDeptId()); |
| | | if (StringUtils.isNotEmpty(phones)){ |
| | | String checkPhones = StringUtils.join(phones, ","); |
| | | add.setCheckIds(checkPhones); |
| | | } |
| | | this.save(add); |
| | | bo.getPeers().add(new EnforcePeer() |
| | | .setPeerType(1) |
| | | .setPeerId(add.getApplyId()) |
| | | .setPeerUser(add.getApplyUser()) |
| | | .setPeerPhone(add.getApplyPhone()) |
| | | .setPeerDeptId(add.getApplyDeptId()) |
| | | .setPeerDeptName(add.getApplyDeptName()) |
| | | ); |
| | | //处理执法人员信息 |
| | | for (EnforcePeer peer : bo.getPeers()) |
| | | { |
| | | peer.setOrderId(add.getOrderId()); |
| | | peer.setPeerDeptName(deptService.getDeptAllName(peer.getPeerDeptId())); |
| | | } |
| | | boolean savePeers = peerService.saveOrUpdateBatch(bo.getPeers()); |
| | | if (savePeers && StringUtils.isNotEmpty(phones)) { |
| | | sendApplyMsg(phones, add.getApplyUser()); |
| | | } |
| | | return savePeers; |
| | | } |
| | | |
| | | @Override//修改 |
| | |
| | | return this.removeByIds(ids); |
| | | } |
| | | |
| | | @Override//月度分布 |
| | | public List<KeyVal> getMonthCount(Long deptId) { |
| | | return orderMapper.getMonthCount(deptId); |
| | | } |
| | | |
| | | @Override//部门分布 |
| | | public List<KeyVal> getDeptCount(String yearMonth) |
| | | @Override |
| | | public List<String> getCheckPhones(Integer checkLevel, Long applyDeptId) |
| | | { |
| | | return orderMapper.getDeptCount(yearMonth); |
| | | return getCheckPhones(checkLevel, applyDeptId, 0); |
| | | } |
| | | |
| | | |
| | | //------------------------------------------------------------------------------------- |
| | | |
| | | |
| | | /** |
| | | * 发送审批短信 |
| | | * @param phones 手机号 |
| | | * @param applyUser 申请人 |
| | | */ |
| | | @Async |
| | | public void sendApplyMsg(List<String> phones, String applyUser) |
| | | { |
| | | String applyMsg = StringUtils.format(StringUtils.format(YPSmsApi.APPLY_TMP, applyUser)); |
| | | phones.forEach(phone->{ |
| | | YPSmsApi.sendSms(phone, applyMsg) ; |
| | | }); |
| | | } |
| | | |
| | | //保存前校验 |
| | | private void validEntityBeforeSave(EnforceOrder entity) |
| | | { |
| | | if (entity.getOrderId()==null){ |
| | | String orderNo = orderNoService.getOrderNo(OrderPre.ZFD.getIndex()); |
| | | entity.setOrderNo(orderNo); |
| | | entity.setCheckDeptId(deptService.getCheckDeptIdByLoginDeptId(entity.getApplyDeptId())); |
| | | } |
| | | if (StringUtils.isEmpty(entity.getApplyDeptName())){ |
| | | entity.setApplyDeptName(deptService.getDeptAllName(entity.getApplyDeptId())); |
| | | } |
| | | if (StringUtils.isEmpty(entity.getExecuteDeptName())){ |
| | | entity.setExecuteDeptName(deptService.getDeptAllName(entity.getExecuteDeptId())); |
| | | } |
| | | if (StringUtils.isEmpty(entity.getCheckDeptName())){ |
| | | entity.setCheckDeptName(deptService.getDeptAllName(entity.getCheckDeptId())); |
| | | } |
| | | |
| | | } |
| | | |
| | | //获取查询参数 |
| | |
| | | qw.like(StringUtils.isNotEmpty(bo.getApplyDeptName()), "apply_dept_name", bo.getApplyDeptName()); |
| | | qw.eq(bo.getApplyTime() != null, "apply_time", bo.getApplyTime()); |
| | | qw.eq(bo.getPlanTime() != null, "plan_time", bo.getPlanTime()); |
| | | qw.eq(bo.getInTime() != null, "in_time", bo.getInTime()); |
| | | qw.eq(bo.getUserNum() != null, "user_num", bo.getUserNum()); |
| | | qw.eq(bo.getWarnStatus() != null, "warn_status", bo.getWarnStatus()); |
| | | qw.eq(StringUtils.isNotEmpty(bo.getWarnReason()), "warn_reason", bo.getWarnReason()); |
| | |
| | | } |
| | | return qw; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取审批人id |
| | | * @param checkLevel 审批级别:默认0 |
| | | * @param deptId 申请部门id |
| | | */ |
| | | private List<String> getCheckPhones(Integer checkLevel, Long deptId, int current) |
| | | { |
| | | if (checkLevel==3){ |
| | | if (current==1){ |
| | | return null; |
| | | } |
| | | checkLevel = 0; |
| | | deptId = deptService.getById(deptId).getParentId(); |
| | | current++; |
| | | getCheckPhones(checkLevel, deptId, current); |
| | | } |
| | | checkLevel++; |
| | | String checkKey = "check_enforce_"; |
| | | List<String> phones = userService.getPhonesByRoleKey(checkKey + checkLevel, deptId); |
| | | if (StringUtils.isNotEmpty(phones)){ |
| | | return phones; |
| | | } |
| | | return getCheckPhones(checkLevel, deptId, current); |
| | | } |
| | | |
| | | |
| | | } |