jiaosong
2023-08-18 26e4b49b3b51e123e9ce2b055c8e0d37d35df260
server/src/main/java/doumeemes/service/business/impl/SalaryParamServiceImpl.java
@@ -8,22 +8,24 @@
import doumeemes.core.utils.Constants;
import doumeemes.core.utils.Utils;
import doumeemes.core.utils.excel.EasyExcelUtil;
import doumeemes.dao.business.DepartmentMapper;
import doumeemes.dao.business.MaterialMapper;
import doumeemes.dao.business.ProceduresMapper;
import doumeemes.dao.business.SalaryParamMapper;
import doumeemes.dao.business.*;
import doumeemes.dao.business.model.*;
import doumeemes.dao.business.vo.SalaryParamVO;
import doumeemes.dao.ext.MaterialExtMapper;
import doumeemes.dao.ext.dto.SalaryParamDTO;
import doumeemes.dao.ext.dto.SalaryParamImportDTO;
import doumeemes.dao.ext.vo.DepartmentExtListVO;
import doumeemes.service.business.DepartmentService;
import doumeemes.service.business.SalaryParamService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import doumeemes.service.ext.DepartmentExtService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -45,29 +47,40 @@
    @Autowired
    private DepartmentMapper departmentMapper;
    @Lazy
    @Autowired
    private DepartmentExtService departmentExtService;
    @Autowired
    private MaterialMapper materialMapper;
    @Autowired
    private MaterialDistributeMapper materialDistributeMapper;
    @Autowired
    private ProceduresMapper proceduresMapper;
    @Override
    public Integer create(SalaryParam salaryParam) {
        LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        SalaryParam insert = new SalaryParam();
        insert.setRootDepartId(principal.getRootDepartment().getId());
        insert.setDepartId(salaryParam.getDepartId());
        insert.setProcedureId(salaryParam.getProcedureId());
        insert.setMaterialId(salaryParam.getMaterialId());
        insert.setDeleted((byte) Constants.ZERO);
        insert.setType(salaryParam.getType());
        if(findOne(insert) != null){
            throw  new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"同一个物料在相同工序不能重复配置哦!");
        }
        insert.setCreateUser(principal.getId());
        insert.setCreateTime(new Date());
        insert.setUpdateUser(principal.getId());
        insert.setUpdateTime(new Date());
        insert.setRemark(salaryParam.getRemark());
        insert.setRootDepartId(salaryParam.getRootDepartId());
        insert.setDepartId(salaryParam.getDepartId());
        insert.setProcedureId(salaryParam.getProcedureId());
        insert.setMaterialId(salaryParam.getMaterialId());
        insert.setSalary(salaryParam.getSalary());
        insert.setSalary(salaryParam.getSalary().multiply(new BigDecimal("100")));
        insert.setNum(salaryParam.getNum());
        insert.setTimes(salaryParam.getTimes());
        insert.setUnqualified(salaryParam.getUnqualified());
@@ -109,10 +122,10 @@
                .set(SalaryParam::getUpdateTime,new Date())
                .set(SalaryParam::getUpdateUser,principal.getId())
                .set(SalaryParam::getType,salaryParam.getType())
                .set(SalaryParam::getDepartId,salaryParam.getDepartId())
                .set(SalaryParam::getMaterialId,salaryParam.getMaterialId())
                .set(SalaryParam::getProcedureId,salaryParam.getProcedureId())
                .set(SalaryParam::getSalary,salaryParam.getSalary())
//                .set(SalaryParam::getDepartId,salaryParam.getDepartId())
//                .set(SalaryParam::getMaterialId,salaryParam.getMaterialId())
//                .set(SalaryParam::getProcedureId,salaryParam.getProcedureId())
                .set(SalaryParam::getSalary,salaryParam.getSalary().multiply(new BigDecimal(100)))
                .set(SalaryParam::getNum,salaryParam.getNum())
                .set(SalaryParam::getTimes,salaryParam.getTimes())
                .set(SalaryParam::getUnqualified,salaryParam.getUnqualified());
@@ -137,6 +150,7 @@
    @Override
    public SalaryParam findOne(SalaryParam salaryParam) {
        QueryWrapper<SalaryParam> wrapper = new QueryWrapper<>(salaryParam);
        wrapper.last("limit 1");
        return salaryParamMapper.selectOne(wrapper);
    }
@@ -149,8 +163,15 @@
    @Override
    public PageData<SalaryParamVO> findPage(PageWrap<SalaryParamDTO> pageWrap) {
        IPage<SalaryParam> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        SalaryParamDTO model = pageWrap.getModel();
        return PageData.from(salaryParamMapper.selectPage(page, model));
        model.setRootDepartId(principal.getRootDepartment().getId());
//        model.setDepartId(principal.getComDepartment().getId());
        IPage<SalaryParamVO> salaryParamVOIPage = salaryParamMapper.selectPage(page, model);
        if (!CollectionUtils.isEmpty(salaryParamVOIPage.getRecords())){
            salaryParamVOIPage.getRecords().forEach(s->s.setSalary(s.getSalary().divide(new BigDecimal(100))));
        }
        return PageData.from(salaryParamVOIPage);
    }
    @Override
@@ -178,7 +199,7 @@
                || Objects.isNull(s.getDepartName())
                || Objects.isNull(s.getMaterialCode())
                || Objects.isNull(s.getProcedureName())
                || Objects.isNull(s.getNUM())){
                || Objects.isNull(s.getNum())){
                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "导入数据内容有误!");
            }
        });
@@ -186,35 +207,55 @@
        for (int i = 0; i < plansList.size(); i++) {
            SalaryParamImportDTO salaryParamImportDTO = plansList.get(i);
            QueryWrapper<Department> wrapper = new QueryWrapper<>();
            wrapper.lambda()
                    .eq(Department::getName,salaryParamImportDTO.getDepartName())
                    .eq(Department::getType,Constants.DEPART_TYPE.factory)
                    .last("limit 1");
            Department department = departmentMapper.selectOne(wrapper);
            if (Objects.isNull(department)){
//
//            QueryWrapper<Department> wrapper = new QueryWrapper<>();
//            wrapper.lambda()
//                    .eq(Department::getName,salaryParamImportDTO.getDepartName())
//                    .eq(Department::getType,Constants.DEPART_TYPE.factory)
//                    .eq(Department::getDeleted,Constants.ZERO)
//                    .last("limit 1");
            Department dparam = new Department();
            dparam.setName(salaryParamImportDTO.getDepartName());
            dparam.setDeleted(Constants.ZERO);
            dparam.setType(Constants.DEPART_TYPE.factory);
            dparam = departmentExtService.findOne(dparam);
            if (Objects.isNull(dparam)){
                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "导入数据内容【公司名称】有误!");
            }
            DepartmentExtListVO department = new DepartmentExtListVO();
            BeanUtils.copyProperties(dparam, department);
            Integer comDepartId = departmentExtService.getComDepartId(department);
            QueryWrapper<Material> materialWrapper = new QueryWrapper<>();
            materialWrapper.lambda()
                    .eq(Material::getCode,salaryParamImportDTO.getMaterialCode())
                    .eq(Material::getRootDepartId,department.getRootId())
                    .eq(Material::getDeleted,Constants.ZERO)
                    .last("limit 1");
            Material material = materialMapper.selectOne(materialWrapper);
            if (Objects.isNull(material)){
                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "导入数据内容【产品编码】有误!");
            }
            if (Objects.nonNull(material) && Objects.equals(material.getName(),salaryParamImportDTO.getMaterialName())){
            if (Objects.nonNull(material) && !Objects.equals(material.getName(),salaryParamImportDTO.getMaterialName())){
                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "导入数据内容【产品名称】有误!");
            }
            QueryWrapper<MaterialDistribute> materialDistributeQueryWrapper = new QueryWrapper<>();
            materialDistributeQueryWrapper.lambda()
                    .eq(MaterialDistribute::getMaterialId,material.getId())
                    .eq(MaterialDistribute::getRootDepartId,department.getRootId())
                    .eq(MaterialDistribute::getDepartId, comDepartId)
                    .eq(MaterialDistribute::getDeleted,Constants.ZERO)
                    .last("limit 1");
            MaterialDistribute materialDistribute = materialDistributeMapper.selectOne(materialDistributeQueryWrapper);
            if (Objects.isNull(materialDistribute)){
                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "导入数据内容【产品编码】有误!");
            }
            QueryWrapper<Procedures> proceduresWrapper = new QueryWrapper<>();
            proceduresWrapper.lambda()
                    .eq(Procedures::getName,salaryParamImportDTO.getProcedureName())
                    .eq(Procedures::getRootDepartId,department.getRootId())
                    .eq(Procedures::getDepartId,department.getId())
//                    .eq(Procedures::getOrgId,department.getId())
                    .last("limit 1");
            Procedures procedures = proceduresMapper.selectOne(proceduresWrapper);
            if (Objects.isNull(procedures)){
@@ -224,12 +265,10 @@
            salaryParam.setRootDepartId(department.getRootId());
            salaryParam.setDepartId(department.getId());
            salaryParam.setProcedureId(procedures.getId());
            salaryParam.setMaterialId(material.getId());
            salaryParam.setMaterialId(materialDistribute.getId());
            salaryParam.setSalary(salaryParamImportDTO.getSalary());
            salaryParam.setNum(new BigDecimal(salaryParamImportDTO.getNUM()));
            salaryParam.setNum(new BigDecimal(salaryParamImportDTO.getNum()));
            salaryParam.setTimes(getIntegerTimes(salaryParamImportDTO.getTimesName()));
            Integer unqualified = Optional.ofNullable(salaryParamImportDTO.getUnqualified()).map(s -> {
                if ("否".equals(s)) {
                    return 0;
@@ -239,7 +278,7 @@
            }).orElse(0);
            salaryParam.setUnqualified(unqualified);
            Integer type = Optional.ofNullable(salaryParamImportDTO.getUnqualified()).map(s -> {
            Integer type = Optional.ofNullable(salaryParamImportDTO.getType()).map(s -> {
                if ("计件".equals(s)) {
                    return 0;
                } else {
@@ -265,7 +304,7 @@
                m = Integer.parseInt(a.substring(hIndex >=0?hIndex+2:0,mIndex));
            }
            if(sIndex > mIndex){
               s = Integer.parseInt(a.substring(mIndex >=0?mIndex+2:0,mIndex));
               s = Integer.parseInt(a.substring(mIndex >= 0 ? mIndex+2 : 0, sIndex));
            }
            return  h*3600+m*60+s;
        }catch (Exception e){