383 lines
17 KiB
Java
383 lines
17 KiB
Java
package com.cnbm.packing.controller;
|
||
|
||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||
import com.cnbm.admin.annotation.LogOperation;
|
||
import com.cnbm.common.constant.Constant;
|
||
import com.cnbm.common.page.PageData;
|
||
import com.cnbm.common.utils.ExcelUtils;
|
||
import com.cnbm.common.utils.Result;
|
||
import com.cnbm.common.validator.AssertUtils;
|
||
import com.cnbm.common.validator.ValidatorUtils;
|
||
import com.cnbm.common.validator.group.AddGroup;
|
||
import com.cnbm.common.validator.group.DefaultGroup;
|
||
import com.cnbm.common.validator.group.UpdateGroup;
|
||
import com.cnbm.packing.dto.ChangePackingBoxDTO;
|
||
import com.cnbm.packing.dto.PowerReportDTO;
|
||
import com.cnbm.packing.dto.WoPackagingBoxSubstrateDTO;
|
||
import com.cnbm.packing.entity.WoPackagingBox;
|
||
import com.cnbm.packing.entity.WoPackagingBoxSubstrate;
|
||
import com.cnbm.packing.excel.WoPackagingBoxSubstrateExcel;
|
||
import com.cnbm.packing.excel.WoPackagingBoxSubstrateManualExcel;
|
||
import com.cnbm.packing.mapper.WoPackagingBoxMapper;
|
||
import com.cnbm.packing.mapper.WoPackagingBoxSubstrateMapper;
|
||
import com.cnbm.packing.param.PowerReportQueryParam;
|
||
import com.cnbm.packing.service.WoPackagingBoxServiceBiz;
|
||
import com.cnbm.packing.service.WoPackagingBoxSubstrateServiceBiz;
|
||
import com.cnbm.packing.vo.PowerReportVo;
|
||
import io.swagger.annotations.Api;
|
||
import io.swagger.annotations.ApiImplicitParam;
|
||
import io.swagger.annotations.ApiImplicitParams;
|
||
import io.swagger.annotations.ApiOperation;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.security.access.prepost.PreAuthorize;
|
||
import org.springframework.web.bind.annotation.*;
|
||
import springfox.documentation.annotations.ApiIgnore;
|
||
|
||
import javax.servlet.http.HttpServletResponse;
|
||
import java.text.DecimalFormat;
|
||
import java.time.format.DateTimeFormatter;
|
||
import java.util.ArrayList;
|
||
import java.time.LocalDateTime;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Objects;
|
||
|
||
|
||
/**
|
||
* 包装箱基æ<C2BA>¿å…³è<C2B3>”表 å‰<C3A5>端控制器
|
||
*
|
||
* @author codeGenerator
|
||
* @since 2023-02-16
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/packing/woPackagingBoxSubstrate")
|
||
@Api(tags="包装箱基æ<EFBFBD>¿å…³è<EFBFBD>”表")
|
||
public class WoPackagingBoxSubstrateController {
|
||
@Autowired
|
||
private WoPackagingBoxSubstrateServiceBiz woPackagingBoxSubstrateService;
|
||
|
||
@Autowired
|
||
private WoPackagingBoxServiceBiz boxServiceBiz;
|
||
|
||
@Autowired
|
||
private WoPackagingBoxSubstrateMapper woPackagingBoxSubstrateMapper;
|
||
|
||
@Autowired
|
||
private WoPackagingBoxMapper woPackagingBoxMapper;
|
||
|
||
@GetMapping("page")
|
||
@ApiOperation("分页")
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = Constant.PAGE, value = "当å‰<EFBFBD>页ç <EFBFBD>,从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
|
||
@ApiImplicitParam(name = Constant.LIMIT, value = "æ¯<EFBFBD>页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
|
||
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排åº<EFBFBD>å—段", paramType = "query", dataTypeClass=String.class) ,
|
||
@ApiImplicitParam(name = Constant.ORDER, value = "排åº<EFBFBD>æ–¹å¼<EFBFBD>,å<EFBFBD>¯é€‰å€¼(ascã€<C3A3>desc)", paramType = "query", dataTypeClass=String.class),
|
||
@ApiImplicitParam(name = "packagingBoxId", value = "包装箱ID,BoxId", paramType = "query", dataTypeClass = String.class),
|
||
@ApiImplicitParam(name = "woSubstrateId", value = "基æ<EFBFBD>¿ID(关è<EFBFBD>”T_SUBSTRATE表)", paramType = "query", dataTypeClass = String.class)
|
||
})
|
||
@PreAuthorize("@ex.hasAuthority('packing:woPackagingBoxSubstrate:page')")
|
||
public Result<PageData<WoPackagingBoxSubstrateDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
|
||
PageData<WoPackagingBoxSubstrateDTO> page = woPackagingBoxSubstrateService.page(params);
|
||
|
||
return new Result<PageData<WoPackagingBoxSubstrateDTO>>().ok(page);
|
||
}
|
||
|
||
@GetMapping("{id}")
|
||
@ApiOperation("ä¿¡æ<EFBFBD>¯")
|
||
@PreAuthorize("@ex.hasAuthority('packing:woPackagingBoxSubstrate:info')")
|
||
public Result<WoPackagingBoxSubstrateDTO> get(@PathVariable("id") Long id){
|
||
WoPackagingBoxSubstrateDTO data = woPackagingBoxSubstrateService.get(id);
|
||
|
||
return new Result<WoPackagingBoxSubstrateDTO>().ok(data);
|
||
}
|
||
|
||
@PostMapping
|
||
@ApiOperation("ä¿<EFBFBD>å˜")
|
||
@LogOperation("ä¿<EFBFBD>å˜")
|
||
@PreAuthorize("@ex.hasAuthority('packing:woPackagingBoxSubstrate:save')")
|
||
public Result<Long> save(@RequestBody WoPackagingBoxSubstrateDTO dto){
|
||
//效验数æ<C2B0>®
|
||
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
||
|
||
woPackagingBoxSubstrateService.save(dto);
|
||
|
||
return new Result<Long>().ok(dto.getId());
|
||
}
|
||
|
||
// @PostMapping
|
||
// @ApiOperation("功率报表")
|
||
// @LogOperation("功率报表查询")
|
||
// public Result<List<PowerReportDTO>> powerReport(@RequestBody PowerReportQueryParam queryParam){
|
||
//
|
||
//
|
||
// List<PowerReportDTO> powerReportDTOS = boxServiceBiz.powerReport(queryParam.getOrderName(), queryParam.getBegin(), queryParam.getEnd());
|
||
// return new Result<List<PowerReportDTO>>().ok(powerReportDTOS);
|
||
// }
|
||
|
||
@PutMapping
|
||
@ApiOperation("修改")
|
||
@LogOperation("修改")
|
||
@PreAuthorize("@ex.hasAuthority('packing:woPackagingBoxSubstrate:update')")
|
||
public Result<Long> update(@RequestBody WoPackagingBoxSubstrateDTO dto){
|
||
//效验数æ<C2B0>®
|
||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
||
|
||
woPackagingBoxSubstrateService.update(dto);
|
||
|
||
return new Result<Long>().ok(dto.getId());
|
||
}
|
||
|
||
@ApiOperation("查询模组档ä½<EFBFBD>统计分布图powerReportTY")
|
||
@LogOperation("查询模组档ä½<EFBFBD>统计分布图powerReportTY")
|
||
@PostMapping("/powerReportTY")
|
||
public Result<Boolean> powerReportTY(@RequestBody PowerReportQueryParam queryParam){
|
||
List<PowerReportDTO> powerReportDTOS = boxServiceBiz.powerReport(queryParam);
|
||
System.out.println(powerReportDTOS);
|
||
return new Result<Boolean>().ok(true);
|
||
}
|
||
|
||
@ApiOperation("查询模组档ä½<EFBFBD>统计分布图")
|
||
@LogOperation("查询模组档ä½<EFBFBD>统计分布图")
|
||
@PostMapping("/powerReport")
|
||
public Result<PowerReportVo> powerReport(@RequestBody PowerReportQueryParam queryParam){
|
||
List<PowerReportDTO> powerReportDTOS = boxServiceBiz.powerReport(queryParam);
|
||
System.out.println(powerReportDTOS.toString());
|
||
List<PowerReportDTO> powerReportList = new ArrayList<>();
|
||
powerReportList.add(new PowerReportDTO(0,"115",0f,"0%"));
|
||
powerReportList.add(new PowerReportDTO(0,"120",0f,"0%"));
|
||
powerReportList.add(new PowerReportDTO(0,"125",0f,"0%"));
|
||
powerReportList.add(new PowerReportDTO(0,"130",0f,"0%"));
|
||
powerReportList.add(new PowerReportDTO(0,"135",0f,"0%"));
|
||
powerReportList.add(new PowerReportDTO(0,"140",0f,"0%"));
|
||
powerReportList.add(new PowerReportDTO(0,"145",0f,"0%"));
|
||
powerReportList.add(new PowerReportDTO(0,"150",0f,"0%"));
|
||
powerReportList.add(new PowerReportDTO(0,"155",0f,"0%"));
|
||
powerReportList.add(new PowerReportDTO(0,"160",0f,"0%"));
|
||
|
||
|
||
for(PowerReportDTO power : powerReportList){
|
||
for(PowerReportDTO inner : powerReportDTOS){
|
||
if(Objects.equals(power.getSubLevel(), inner.getSubLevel())){
|
||
power.setProportion(inner.getProportion());
|
||
power.setSubNum(inner.getSubNum());
|
||
power.setSumPMPP(inner.getSumPMPP());
|
||
power.setSubLevel(inner.getSubLevel());
|
||
}
|
||
}
|
||
}
|
||
|
||
System.out.println(powerReportList.toString());
|
||
PowerReportVo powerReportVo = new PowerReportVo();
|
||
Float totalLevelPower = new Float(0);
|
||
Float totalCompensatePower = new Float(0);
|
||
Float diversePower = new Float(0);
|
||
Integer totalSubNum = 0;
|
||
for(PowerReportDTO power : powerReportList){
|
||
Integer subLevel = Integer.valueOf(power.getSubLevel());
|
||
Integer subNum = power.getSubNum();
|
||
if(power.getSumPMPP()==null){
|
||
return new Result<PowerReportVo>().error("基æ<EFBFBD>¿ç‰çº§ï¼š"+subLevel+",基æ<C2BA>¿æ•°é‡<C3A9>:"+subNum+", 的总和为null");
|
||
}
|
||
Float sumPMPP = power.getSumPMPP();
|
||
totalLevelPower += subLevel*subNum;
|
||
totalCompensatePower += sumPMPP*subNum;
|
||
totalSubNum+= subNum;
|
||
}
|
||
for(PowerReportDTO power : powerReportList){
|
||
if(power.getSubNum()==0 ||totalSubNum ==0 ){
|
||
power.setProportion("0%");
|
||
}else {
|
||
Float prop = (Float.valueOf(power.getSubNum())/Float.valueOf(totalSubNum))*100;
|
||
DecimalFormat df = new DecimalFormat("0.00");
|
||
String propS = df.format(prop)+"%";
|
||
power.setProportion(propS);
|
||
}
|
||
}
|
||
|
||
|
||
diversePower = totalCompensatePower - totalLevelPower;
|
||
powerReportVo.setPowerReports(powerReportList);
|
||
powerReportVo.setDiversePower(diversePower);
|
||
powerReportVo.setTotalCompensatePower(totalCompensatePower);
|
||
powerReportVo.setTotalLevelPower(totalLevelPower);
|
||
|
||
return new Result<PowerReportVo>().ok(powerReportVo);
|
||
}
|
||
|
||
@ApiOperation("查询模组档ä½<EFBFBD>统计分布图-获å<C2B7>–ordername列表")
|
||
@LogOperation("查询模组档ä½<EFBFBD>统计分布图-获å<C2B7>–ordername列表")
|
||
@PostMapping("/orderNameList")
|
||
public Result<List<String>> orderNameList(){
|
||
List<String> powerReportDTOS = boxServiceBiz.orderNameList();
|
||
return new Result<List<String>>().ok(powerReportDTOS);
|
||
}
|
||
|
||
@DeleteMapping
|
||
@ApiOperation("åˆ é™¤")
|
||
@LogOperation("åˆ é™¤")
|
||
@PreAuthorize("@ex.hasAuthority('packing:woPackagingBoxSubstrate:delete')")
|
||
public Result delete(@RequestBody Long[] ids){
|
||
//效验数æ<C2B0>®
|
||
AssertUtils.isArrayEmpty(ids, "id");
|
||
|
||
woPackagingBoxSubstrateService.delete(ids);
|
||
|
||
return new Result();
|
||
}
|
||
|
||
@GetMapping("export")
|
||
@ApiOperation("导出")
|
||
@LogOperation("导出")
|
||
@PreAuthorize("@ex.hasAuthority('packing:woPackagingBoxSubstrate:export')")
|
||
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
|
||
List<WoPackagingBoxSubstrateDTO> list = woPackagingBoxSubstrateService.list(params);
|
||
|
||
ExcelUtils.exportExcelToTarget(response, null, list, WoPackagingBoxSubstrateExcel.class);
|
||
}
|
||
|
||
@PostMapping("removeSubstrate/{id}")
|
||
@ApiOperation("移箱")
|
||
@LogOperation("移箱")
|
||
public Result removeSubstrate(@PathVariable("id") Long id){
|
||
|
||
woPackagingBoxSubstrateService.removeSubstrate(id);
|
||
|
||
return new Result();
|
||
}
|
||
|
||
@PostMapping("insertSubstrate")
|
||
@ApiOperation("å<EFBFBD>ˆç®±")
|
||
@LogOperation("å<EFBFBD>ˆç®±")
|
||
public Result insertSubstrate(@RequestBody ChangePackingBoxDTO dto){
|
||
|
||
//验è¯<C3A8>模组是å<C2AF>¦å˜åœ¨
|
||
QueryWrapper<WoPackagingBoxSubstrate> substrateQueryWrapper1 = new QueryWrapper<>();
|
||
substrateQueryWrapper1.eq(WoPackagingBoxSubstrate.WO_SUBSTRATE_ID, dto.getWoSubstrateId());
|
||
if(woPackagingBoxSubstrateMapper.selectCount(substrateQueryWrapper1 )== 0){
|
||
return new Result().error(1,"该模组ä¸<EFBFBD>å˜åœ¨,请é‡<C3A9>新输入");
|
||
}
|
||
WoPackagingBoxSubstrate substrate = woPackagingBoxSubstrateMapper.selectList(substrateQueryWrapper1).get(0);
|
||
//验è¯<C3A8>模组是å<C2AF>¦åŒ…装箱为空
|
||
if(substrate.getPackagingBoxId()!=null){
|
||
return new Result().error(1,"该模组在其他包装箱内");
|
||
}
|
||
|
||
//验è¯<C3A8>slot是å<C2AF>¦è¢«å<C2AB> 用
|
||
QueryWrapper<WoPackagingBoxSubstrate> substrateQueryWrapper2 = new QueryWrapper<>();
|
||
substrateQueryWrapper2.eq(StringUtils.isNotBlank(dto.getPackagingBoxId()), WoPackagingBoxSubstrate.PACKAGING_BOX_ID, dto.getPackagingBoxId());
|
||
substrateQueryWrapper2.eq(ObjectUtils.isNotNull(dto.getSlot()), WoPackagingBoxSubstrate.SLOT, dto.getSlot());
|
||
if(woPackagingBoxSubstrateMapper.selectCount(substrateQueryWrapper2) != 0){
|
||
return new Result().error(1,"该slot已被å<EFBFBD> 用");
|
||
}
|
||
|
||
//验è¯<C3A8>该模组的线体ã€<C3A3>功率ç‰çº§æ˜¯å<C2AF>¦BoxID的线体ã€<C3A3>功率ç‰çº§ä¸€è‡´ï¼Œä¸€è‡´ï¼Œä¿<C3A4>å˜æˆ<C3A6>功,数æ<C2B0>®å<C2AE>‘生更新。ä¸<C3A4>一致,则显示ä¿<C3A4>å˜å¤±è´¥ï¼Œæ•°æ<C2B0>®ä¸<C3A4>å<EFBFBD>‘生更新
|
||
String packagingBoxId = dto.getPackagingBoxId();
|
||
QueryWrapper<WoPackagingBox> boxQueryWrapper = new QueryWrapper<>();
|
||
boxQueryWrapper.eq(StringUtils.isNotBlank(packagingBoxId), WoPackagingBox.BOX_NO, packagingBoxId);
|
||
WoPackagingBox box = woPackagingBoxMapper.selectList(boxQueryWrapper).get(0);
|
||
|
||
if((substrate.getLineBody()==box.getLineBody()) && (substrate.getPowerLevel().equals(box.getPowerLevel())) )
|
||
{
|
||
dto.setId(substrate.getId());
|
||
woPackagingBoxSubstrateService.insertSubstrate(dto);
|
||
return new Result();
|
||
}
|
||
else{
|
||
return new Result().error(1,"ä¿<EFBFBD>å˜å¤±è´¥");
|
||
}
|
||
}
|
||
|
||
@PostMapping("replaceSubstrate")
|
||
@ApiOperation("æ<EFBFBD>¢ç®±")
|
||
@LogOperation("æ<EFBFBD>¢ç®±")
|
||
public Result replaceSubstrate(@RequestBody ChangePackingBoxDTO[] dtos){
|
||
|
||
woPackagingBoxSubstrateService.replaceSubstrate(dtos);
|
||
|
||
return new Result();
|
||
}
|
||
|
||
@PostMapping("slotValidation")
|
||
@ApiOperation("slot是å<EFBFBD>¦å<EFBFBD> 用验è¯<EFBFBD>")
|
||
public boolean slotValidation(@RequestBody ChangePackingBoxDTO dto){
|
||
|
||
QueryWrapper<WoPackagingBoxSubstrate> wrapper = new QueryWrapper<>();
|
||
wrapper.eq(StringUtils.isNotBlank(dto.getPackagingBoxId()), WoPackagingBoxSubstrate.PACKAGING_BOX_ID, dto.getPackagingBoxId());
|
||
wrapper.eq(ObjectUtils.isNotNull(dto.getSlot()), WoPackagingBoxSubstrate.SLOT, dto.getSlot());
|
||
if(woPackagingBoxSubstrateMapper.selectCount(wrapper) == 0){
|
||
return true;
|
||
}
|
||
else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
@PostMapping("insertSubstrateManual")
|
||
@ApiOperation("手动装箱")
|
||
@LogOperation("手动装箱")
|
||
public Result insertSubstrateManual(@RequestBody ChangePackingBoxDTO[] dtos){
|
||
|
||
woPackagingBoxSubstrateService.insertSubstrateManual(dtos);
|
||
|
||
return new Result();
|
||
}
|
||
|
||
@PostMapping("updateSubstrateManual")
|
||
@ApiOperation("手动装箱编辑")
|
||
@LogOperation("手动装箱编辑")
|
||
public Result updateSubstrateManual(@RequestBody ChangePackingBoxDTO[] dtos){
|
||
|
||
woPackagingBoxSubstrateService.updateSubstrateManual(dtos);
|
||
|
||
return new Result();
|
||
}
|
||
|
||
@GetMapping("substrateList")
|
||
@ApiOperation("装箱å<EFBFBD>•ä¿¡æ<EFBFBD>¯æŸ¥è¯¢")
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataTypeClass = LocalDateTime.class),
|
||
@ApiImplicitParam(name = "endTime", value = "结æ<EFBFBD>Ÿæ—¶é—´", paramType = "query", dataTypeClass = LocalDateTime.class),
|
||
@ApiImplicitParam(name = "model", value = "模å¼<EFBFBD>,1-手动模å¼<C3A5>ï¼›2-自动模å¼<C3A5>", paramType = "query", dataTypeClass = Integer.class),
|
||
@ApiImplicitParam(name = "packagingBoxId", value = "包装箱ID,BoxId", paramType = "query", dataTypeClass = String.class),
|
||
@ApiImplicitParam(name = "woSubstrateId", value = "基æ<EFBFBD>¿ID(关è<EFBFBD>”T_SUBSTRATE表)", paramType = "query", dataTypeClass = String.class)
|
||
|
||
})
|
||
public List<WoPackagingBoxSubstrateDTO> substrateList(@ApiIgnore @RequestParam Map<String, Object> params){
|
||
return woPackagingBoxSubstrateService.substrateList(params);
|
||
}
|
||
|
||
@GetMapping("exportPackingInfo")
|
||
@ApiOperation("装箱å<EFBFBD>•ä¿¡æ<EFBFBD>¯å¯¼å‡º")
|
||
@LogOperation("装箱å<EFBFBD>•ä¿¡æ<EFBFBD>¯å¯¼å‡º")
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataTypeClass = LocalDateTime.class),
|
||
@ApiImplicitParam(name = "endTime", value = "结æ<EFBFBD>Ÿæ—¶é—´", paramType = "query", dataTypeClass = LocalDateTime.class),
|
||
@ApiImplicitParam(name = "model", value = "模å¼<EFBFBD>,1-手动模å¼<C3A5>ï¼›2-自动模å¼<C3A5>", paramType = "query", dataTypeClass = Integer.class),
|
||
@ApiImplicitParam(name = "packagingBoxId", value = "包装箱ID,BoxId", paramType = "query", dataTypeClass = String.class),
|
||
@ApiImplicitParam(name = "woSubstrateId", value = "基æ<EFBFBD>¿ID(关è<EFBFBD>”T_SUBSTRATE表)", paramType = "query", dataTypeClass = String.class)
|
||
|
||
})
|
||
public void exportPackingInfo(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
|
||
List<WoPackagingBoxSubstrateDTO> list = woPackagingBoxSubstrateService.substrateList(params);
|
||
if(list.size()>0) {
|
||
//包装箱创建时间 最近打å<E2809C>°æ—¶é—´ 转化
|
||
for(WoPackagingBoxSubstrateDTO dto:list){
|
||
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||
if(dto.getBoxCreateTime()!=null){
|
||
dto.setBoxCreateTime1(df.format(dto.getBoxCreateTime()));
|
||
}
|
||
if(dto.getPrintTime()!=null){
|
||
dto.setPrintTime1(df.format(dto.getPrintTime()));
|
||
}
|
||
}
|
||
if(Integer.parseInt(params.get("model").toString())==1){
|
||
ExcelUtils.exportExcelToTarget(response, "手动装箱å<EFBFBD>•ä¿¡æ<EFBFBD>¯", list, WoPackagingBoxSubstrateManualExcel.class);
|
||
}
|
||
else {
|
||
ExcelUtils.exportExcelToTarget(response, "自动装箱å<EFBFBD>•ä¿¡æ<EFBFBD>¯", list, WoPackagingBoxSubstrateExcel.class);
|
||
}
|
||
}
|
||
}
|
||
} |