cigs4/ym-packing/src/main/java/com/cnbm/packing/controller/WoPackagingBoxSubstrateController.java
2023-02-28 10:19:12 +08:00

220 lines
9.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.WoPackagingBoxSubstrateDTO;
import com.cnbm.packing.entity.WoPackagingBox;
import com.cnbm.packing.entity.WoPackagingBoxSubstrate;
import com.cnbm.packing.excel.WoPackagingBoxSubstrateExcel;
import com.cnbm.packing.mapper.WoPackagingBoxMapper;
import com.cnbm.packing.mapper.WoPackagingBoxSubstrateMapper;
import com.cnbm.packing.service.WoPackagingBoxSubstrateServiceBiz;
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.util.List;
import java.util.Map;
/**
* 包装箱基板关联表 前端控制器
*
* @author codeGenerator
* @since 2023-02-16
*/
@RestController
@RequestMapping("/packing/woPackagingBoxSubstrate")
@Api(tags="包装箱基板关联表")
public class WoPackagingBoxSubstrateController {
@Autowired
private WoPackagingBoxSubstrateServiceBiz woPackagingBoxSubstrateService;
@Autowired
private WoPackagingBoxSubstrateMapper woPackagingBoxSubstrateMapper;
@Autowired
private WoPackagingBoxMapper woPackagingBoxMapper;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class),
@ApiImplicitParam(name = "packagingBoxId", value = "包装箱IDBoxId", paramType = "query", dataTypeClass = String.class),
@ApiImplicitParam(name = "woSubstrateId", value = "基板ID关联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("信息")
@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("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('packing:woPackagingBoxSubstrate:save')")
public Result<Long> save(@RequestBody WoPackagingBoxSubstrateDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
woPackagingBoxSubstrateService.save(dto);
return new Result<Long>().ok(dto.getId());
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('packing:woPackagingBoxSubstrate:update')")
public Result<Long> update(@RequestBody WoPackagingBoxSubstrateDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
woPackagingBoxSubstrateService.update(dto);
return new Result<Long>().ok(dto.getId());
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('packing:woPackagingBoxSubstrate:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
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("合箱")
@LogOperation("合箱")
public Result insertSubstrate(@RequestBody ChangePackingBoxDTO dto){
String woSubstrateId = dto.getWoSubstrateId();
//验证模组是否存在
QueryWrapper<WoPackagingBoxSubstrate> substrateQueryWrapper1 = new QueryWrapper<>();
substrateQueryWrapper1.eq(StringUtils.isNotBlank(woSubstrateId), WoPackagingBoxSubstrate.WO_SUBSTRATE_ID, woSubstrateId);
if(woPackagingBoxSubstrateMapper.selectCount(substrateQueryWrapper1 )== 0){
return new Result().error(1,"该模组不存在,请重新输入");
}
WoPackagingBoxSubstrate substrate = woPackagingBoxSubstrateMapper.selectList(substrateQueryWrapper1).get(0);
//验证模组是否包装箱为空
if(substrate.getPackagingBoxId()!=null){
return new Result().error(1,"该模组在其他包装箱内");
}
//验证slot是否被占用
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已被占用");
}
//验证该模组的线体、功率等级是否BoxID的线体、功率等级一致一致保存成功数据发生更新。不一致则显示保存失败数据不发生更新
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,"保存失败");
}
}
@PostMapping("replaceSubstrate")
@ApiOperation("换箱")
@LogOperation("换箱")
public Result replaceSubstrate(@RequestBody ChangePackingBoxDTO[] dtos){
woPackagingBoxSubstrateService.replaceSubstrate(dtos);
return new Result();
}
@PostMapping("slotValidation")
@ApiOperation("slot是否占用验证")
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 dto){
woPackagingBoxSubstrateService.insertSubstrateManual(dto);
return new Result();
}
}