package org.jeecg.modules.mdc.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.apache.commons.lang.StringUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.jeecg.common.system.vo.LoginUser;
|
import org.jeecg.modules.mdc.entity.MdcEquipment;
|
import org.jeecg.modules.mdc.entity.MdcPassRate;
|
import org.jeecg.modules.mdc.entity.MdcStandardProcessDuration;
|
import org.jeecg.modules.mdc.mapper.MdcPassRateMapper;
|
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
|
import org.jeecg.modules.mdc.service.IMdcPassRateService;
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.List;
|
|
|
/**
|
* @Description: 合格率表
|
* @Author: lius
|
* @Date: 2023-07-18
|
* @Version: V1.0
|
*/
|
@Service
|
public class MdcPassRateServiceImpl extends ServiceImpl<MdcPassRateMapper, MdcPassRate> implements IMdcPassRateService {
|
|
@Resource
|
private IMdcEquipmentService mdcEquipmentService;
|
|
@Override
|
public IPage<MdcPassRate> pageList(String userId, Page<MdcPassRate> page, MdcPassRate mdcPassRate, HttpServletRequest req) {
|
List<String> equipmentIds = new ArrayList<>();
|
if (StringUtils.isNotEmpty(mdcPassRate.getParentId()) && StringUtils.isEmpty(mdcPassRate.getEquipmentId())) {
|
if ("2".equals(mdcPassRate.getTypeTree())) {
|
//部门层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcPassRate.getParentId());
|
} else {
|
//产线层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcPassRate.getParentId());
|
}
|
} else if (StringUtils.isNotEmpty(mdcPassRate.getEquipmentId())) {
|
//单台设备信息
|
mdcPassRate.setMdcSectionIds(Collections.singletonList(mdcPassRate.getEquipmentId()));
|
} else {
|
//查询用户拥有的所有设备信息
|
if ("2".equals(mdcPassRate.getTypeTree())) {
|
//部门层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
|
} else {
|
//产线层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
|
}
|
}
|
|
if (mdcPassRate.getMdcSectionIds() == null || mdcPassRate.getMdcSectionIds().isEmpty()) {
|
mdcPassRate.setMdcSectionIds(equipmentIds);
|
}
|
|
if (mdcPassRate.getMdcSectionIds() == null || mdcPassRate.getMdcSectionIds().isEmpty()) {
|
return null;
|
}
|
|
return this.baseMapper.pageList(page, mdcPassRate);
|
}
|
|
/**
|
* 添加数据
|
*
|
* @param mdcPassRate
|
* @return
|
*/
|
@Override
|
public boolean addPassRate(MdcPassRate mdcPassRate) {
|
boolean result = false;
|
String[] equipmentIds = mdcPassRate.getEquipmentIds().split(",");
|
for (String equipmentId : equipmentIds) {
|
MdcEquipment mdcEquipment = mdcEquipmentService.findEquipmentNameByEquipmentId(equipmentId);
|
MdcPassRate passRate = new MdcPassRate();
|
BeanUtils.copyProperties(mdcPassRate, passRate);
|
passRate.setEquipmentId(mdcEquipment.getEquipmentId());
|
passRate.setEquipmentName(mdcEquipment.getEquipmentName());
|
if (passRate.getProcessQuantity() == null || passRate.getProcessQuantity() == 0) {
|
passRate.setPassRate(new BigDecimal("0"));
|
} else {
|
if (passRate.getUnqualifiedQuantity() == null || passRate.getUnqualifiedQuantity() == 0) {
|
passRate.setPassRate(new BigDecimal("1"));
|
} else {
|
passRate.setPassRate(new BigDecimal("1").subtract(new BigDecimal(passRate.getUnqualifiedQuantity()).divide(new BigDecimal(passRate.getProcessQuantity()), 4, BigDecimal.ROUND_HALF_UP)));
|
}
|
}
|
boolean b = super.save(passRate);
|
if (b) {
|
result = true;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* 编辑数据
|
*
|
* @param mdcPassRate
|
* @return
|
*/
|
@Override
|
public boolean updatePassRate(MdcPassRate mdcPassRate) {
|
if (mdcPassRate.getProcessQuantity() == null || mdcPassRate.getProcessQuantity() == 0) {
|
mdcPassRate.setPassRate(new BigDecimal("0"));
|
} else {
|
if (mdcPassRate.getUnqualifiedQuantity() == null || mdcPassRate.getUnqualifiedQuantity() == 0) {
|
mdcPassRate.setPassRate(new BigDecimal("1"));
|
} else {
|
mdcPassRate.setPassRate(new BigDecimal("1").subtract(new BigDecimal(mdcPassRate.getUnqualifiedQuantity()).divide(new BigDecimal(mdcPassRate.getProcessQuantity()), 4, BigDecimal.ROUND_HALF_UP)));
|
}
|
}
|
return super.updateById(mdcPassRate);
|
}
|
|
/**
|
* 导出
|
*
|
* @param userId
|
* @param mdcPassRate
|
* @return
|
*/
|
@Override
|
public ModelAndView exportXls(String userId, MdcPassRate mdcPassRate) {
|
LambdaQueryWrapper<MdcPassRate> queryWrapper = new LambdaQueryWrapper<>();
|
List<String> equipmentIds = new ArrayList<>();
|
if (StringUtils.isNotEmpty(mdcPassRate.getParentId()) && StringUtils.isEmpty(mdcPassRate.getEquipmentId())) {
|
if ("2".equals(mdcPassRate.getTypeTree())) {
|
//部门层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcPassRate.getParentId());
|
} else {
|
//产线层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcPassRate.getParentId());
|
}
|
} else if (StringUtils.isNotEmpty(mdcPassRate.getEquipmentId())) {
|
//单台设备信息
|
mdcPassRate.setMdcSectionIds(Collections.singletonList(mdcPassRate.getEquipmentId()));
|
} else {
|
//查询用户所拥有的所有设备信息
|
if ("2".equals(mdcPassRate.getTypeTree())) {
|
//部门层级
|
equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
|
} else {
|
equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
|
}
|
}
|
if (mdcPassRate.getMdcSectionIds() == null || mdcPassRate.getMdcSectionIds().isEmpty()) {
|
mdcPassRate.setMdcSectionIds(equipmentIds);
|
}
|
if (mdcPassRate.getMdcSectionIds() == null || mdcPassRate.getMdcSectionIds().isEmpty()) {
|
return null;
|
} else {
|
queryWrapper.in(MdcPassRate::getEquipmentId, mdcPassRate.getMdcSectionIds());
|
}
|
if (StringUtils.isNotEmpty(mdcPassRate.getEquipmentId())) {
|
queryWrapper.like(MdcPassRate::getEquipmentId, mdcPassRate.getEquipmentId());
|
}
|
if (StringUtils.isNotEmpty(mdcPassRate.getEquipmentName())) {
|
queryWrapper.like(MdcPassRate::getEquipmentName, mdcPassRate.getEquipmentName());
|
}
|
if (StringUtils.isNotEmpty(mdcPassRate.getStartTime()) && StringUtils.isNotEmpty(mdcPassRate.getEndTime())) {
|
queryWrapper.between(MdcPassRate::getEfficientDate, mdcPassRate.getStartTime(), mdcPassRate.getEndTime());
|
}
|
queryWrapper.orderByAsc(MdcPassRate::getEquipmentName).orderByDesc(MdcPassRate::getEfficientDate);
|
// Step.2 AutoPoi 导出Excel
|
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
List<MdcPassRate> mdcPassRates = this.baseMapper.selectList(queryWrapper);
|
// 导出文件名称
|
mv.addObject(NormalExcelConstants.FILE_NAME, "合格率列表");
|
mv.addObject(NormalExcelConstants.CLASS, MdcPassRate.class);
|
//获取当前登录用户
|
//update-begin---author:wangshuai ---date:20211227 for:[JTC-116]导出人写死了------------
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("合格率列表数据", "导出人:" + user.getRealname(), "导出信息"));
|
//update-end---author:wangshuai ---date:20211227 for:[JTC-116]导出人写死了------------
|
mv.addObject(NormalExcelConstants.DATA_LIST, mdcPassRates);
|
return mv;
|
}
|
}
|