package com.project.enforce.service.impl; import cn.hutool.core.convert.Convert; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.project.common.core.domain.entity.SysUser; import com.project.common.exception.base.BaseException; import com.project.common.utils.DateUtils; import com.project.common.utils.SecurityUtils; import com.project.common.utils.StringUtils; import com.project.enforce.domain.EnforceComplaintLog; import com.project.enforce.domain.bo.editBo.ComplaintResultBo; import com.project.enforce.domain.bo.editBo.EnforceComplaintLogBo; import com.project.enforce.domain.bo.queryBo.EnforceComplaintLogQueryBo; import com.project.enforce.domain.vo.EnforceComplaintLogVo; import com.project.enforce.domain.vo.OrderNodeVo; import com.project.enforce.mapper.EnforceComplaintLogMapper; import com.project.enforce.service.IEnforceComplaintLogService; import com.project.system.service.ISysDeptService; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** * 投诉记录Service业务层处理 * * @author manton */ @Service @RequiredArgsConstructor(onConstructor_ = @Autowired) public class EnforceComplaintLogServiceImpl extends ServiceImpl implements IEnforceComplaintLogService { private final ISysDeptService deptService; @Override//列表查询 public List queryList(EnforceComplaintLogQueryBo bo) { QueryWrapper qw = getQw(bo); List list = this.list(qw); return Convert.toList(EnforceComplaintLogVo.class , list); } @Override//id查询 public EnforceComplaintLogVo queryById(Long id) { EnforceComplaintLog db = this.baseMapper.selectById(id); return Convert.convert(EnforceComplaintLogVo.class , db); } @Override//添加 @Transactional public Boolean insertByBo(EnforceComplaintLogBo bo) { EnforceComplaintLog add = Convert.convert(EnforceComplaintLog.class, bo); validEntityBeforeSave(add); return this.save(add); } @Override//修改 @Transactional public Boolean updateByBo(EnforceComplaintLogBo bo) { EnforceComplaintLog update = Convert.convert(EnforceComplaintLog.class, bo); validEntityBeforeSave(update); return this.updateById(update); } @Override//删除 @Transactional public Boolean deleteByIds(Collection ids) { //做一些业务上的校验,判断是否需要校验 return this.removeByIds(ids); } @Override//投诉单节点 public List orderNodeList(Long id) { List vos = new ArrayList<>(); EnforceComplaintLog order = this.getById(id); if (order.getComplaintTime()!=null){ vos.add(new OrderNodeVo("发起投诉",order.getCompanyUser(),order.getComplaintTime(), null)); } if (order.getInTime()!=null){ vos.add(new OrderNodeVo("响应投诉",order.getInUser(),order.getInTime(), null)); } if (order.getResultTime()!=null){ vos.add(new OrderNodeVo("投诉结果",order.getExecuteUser(),order.getResultTime(), order.getComplaintResult())); } return vos; } @Override//响应投诉 @Transactional public Boolean inComplaint(ComplaintResultBo bo) { SysUser loginUser = SecurityUtils.getLoginUser().getUser(); return this.update(lu() .set(EnforceComplaintLog::getInId,loginUser.getUserId()) .set(EnforceComplaintLog::getInUser,loginUser.getNickName()) .set(EnforceComplaintLog::getInTime, DateUtils.getNowDate()) .set(EnforceComplaintLog::getComplaintStatus, 1) .eq(EnforceComplaintLog::getId, bo.getId()) ); } @Override//处理结果 @Transactional public Boolean doComplaint(ComplaintResultBo bo) { if (StringUtils.isEmpty(bo.getResult())){ throw new BaseException("请填写处理结果"); } SysUser loginUser = SecurityUtils.getLoginUser().getUser(); return this.update(lu() .set(EnforceComplaintLog::getResultId,loginUser.getUserId()) .set(EnforceComplaintLog::getResultUser,loginUser.getNickName()) .set(EnforceComplaintLog::getResultTime, DateUtils.getNowDate()) .set(EnforceComplaintLog::getComplaintResult, bo.getResult()) .eq(EnforceComplaintLog::getId, bo.getId()) ); } //------------------------------------------------------------------------------------- //保存前校验 private void validEntityBeforeSave(EnforceComplaintLog entity) { if (StringUtils.isEmpty(entity.getExecuteDeptName()) && entity.getExecuteDeptName()!=null){ entity.setExecuteDeptName(deptService.getDeptAllName(entity.getExecuteDeptId())); } if (entity.getCompanyId()==null || StringUtils.isEmpty(entity.getCompanyName()) || StringUtils.isEmpty(entity.getCompanyUser()) || StringUtils.isEmpty(entity.getCompanyPhone()) ){ throw new BaseException("投诉企业不能为空!"); } if (entity.getExecuteDeptId() == null || StringUtils.isEmpty(entity.getExecuteDeptName()) ){ throw new BaseException("投诉单位不能为空!"); } if (StringUtils.isEmpty(entity.getComplaintType())){ throw new BaseException("请选择要投诉类型!"); } if (StringUtils.isEmpty(entity.getComplaintReason())){ throw new BaseException("请填写投诉内容!"); } if (entity.getId()==null){ if (entity.getOrderId()!=null){ //执法单投诉 int count = this.count(lq().eq(EnforceComplaintLog::getOrderId, entity.getOrderId())); if (count >0){ throw new BaseException("该执法单已投诉!"); } } entity.setComplaintTime(DateUtils.getNowDate()); } } //获取查询参数 private QueryWrapper getQw(EnforceComplaintLogQueryBo bo) { QueryWrapper qw = Wrappers.query(); qw.eq(StringUtils.isNotEmpty(bo.getOrderId()), "order_id", bo.getOrderId()); qw.eq(StringUtils.isNotEmpty(bo.getOrderNo()), "order_no", bo.getOrderNo()); qw.eq(StringUtils.isNotEmpty(bo.getEnforceReason()), "enforce_reason", bo.getEnforceReason()); qw.eq(bo.getCompanyId() != null, "company_id", bo.getCompanyId()); qw.like(StringUtils.isNotEmpty(bo.getCompanyName()), "company_name", bo.getCompanyName()); qw.eq(StringUtils.isNotEmpty(bo.getCompanyUser()), "company_user", bo.getCompanyUser()); qw.eq(StringUtils.isNotEmpty(bo.getCompanyPhone()), "company_phone", bo.getCompanyPhone()); qw.eq(bo.getExecuteUser() != null, "execute_user", bo.getExecuteUser()); qw.eq(bo.getExecutePhone() != null, "execute_phone", bo.getExecutePhone()); qw.like(bo.getExecuteDeptName() != null, "execute_dept_name", bo.getExecuteDeptName()); qw.eq(StringUtils.isNotEmpty(bo.getComplaintType()), "complaint_type", bo.getComplaintType()); qw.eq(StringUtils.isNotEmpty(bo.getComplaintReason()), "complaint_reason", bo.getComplaintReason()); qw.eq(bo.getComplaintStatus() != null, "complaint_status", bo.getComplaintStatus()); qw.eq(StringUtils.isNotEmpty(bo.getReturnReason()), "return_reason", bo.getReturnReason()); qw.eq(StringUtils.isNotEmpty(bo.getComplaintResult()), "complaint_result", bo.getComplaintResult()); if (StringUtils.isNotEmpty(bo.getIsAsc()) && StringUtils.isNotEmpty(bo.getOrderByColumn())){ if ("acs".equals(bo.getIsAsc())) { qw.orderByAsc(bo.getOrderByColumn()); } else if ("desc".equals(bo.getIsAsc())) { qw.orderByDesc(bo.getOrderByColumn()); } } return qw; } }