package com.zt.life.modules.mainPart.basicInfo.controller; import com.zt.common.annotation.LogOperation; import com.zt.common.constant.Constant; import com.zt.common.annotation.QueryParam; import com.zt.common.db.query.QueryFilter; import com.zt.common.servlet.Result; import com.zt.common.utils.CacheUtils; import com.zt.common.utils.UUIDUtil; import com.zt.common.validator.AssertUtils; import com.zt.common.validator.ValidatorUtils; import com.zt.common.validator.group.AddGroup; import com.zt.common.validator.group.DefaultGroup; import com.zt.common.validator.group.UpdateGroup; import com.zt.life.core.service.ZtProductService; import com.zt.life.dto.ImportErrDto; import com.zt.life.modules.mainPart.basicInfo.model.ParamData; import com.zt.life.modules.mainPart.basicInfo.model.ProductImg; import com.zt.life.modules.mainPart.basicInfo.model.XhProductModel; import com.zt.life.modules.mainPart.basicInfo.service.ParamDataService; import com.zt.life.modules.mainPart.basicInfo.service.XhProductModelService; import com.zt.life.modules.mainPart.sysPictureBase.service.SysPictureBaseService; import com.zt.life.util.ImportUtil; import com.zt.modules.oss.service.SysOssService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; import java.util.Map; /** * product_model * * @author zt generator * @since 1.0.0 2024-02-29 */ @RestController @RequestMapping("/basicInfo/XhProductModel/") @Api(tags = "product_model") public class XhProductModelController { @Autowired private XhProductModelService xhProductModelService; @Autowired private SysPictureBaseService sysPictureBaseService; @Autowired private ParamDataService paramDataService; @GetMapping("page") @ApiOperation("分页") @ApiImplicitParams({ @ApiImplicitParam(name = Constant.Q.ORDER_FIELD, value = Constant.QV.ORDER_FIELD, dataType = Constant.QT.STRING), @ApiImplicitParam(name = Constant.Q.ORDER, value = Constant.QV.ORDER, dataType = Constant.QT.STRING), @ApiImplicitParam(name = "name", value = "名称", dataType = Constant.QT.STRING, format = "NAME^LK"), @ApiImplicitParam(name = "productType", value = "节点类型", dataType = Constant.QT.STRING, format = "product_type^EQ"), @ApiImplicitParam(name = "pid", value = "上级ID", dataType = Constant.QT.STRING) }) public Result> page(@ApiIgnore @QueryParam QueryFilter queryFilter) { return Result.ok(xhProductModelService.page(queryFilter)); } @GetMapping("tree") public Result> getTreeList(Boolean showXdy, Integer ztShow, Long productId) { List list = xhProductModelService.getAllTree(showXdy, ztShow, productId); return Result.ok(list); } @GetMapping("getProduct") public Result> getProduct(Long productId) { List list = xhProductModelService.getProduct(productId); return Result.ok(list); } @GetMapping("{id}") @ApiOperation("信息") public Result get(@PathVariable("id") Long id) { XhProductModel data = xhProductModelService.get(id); if (data.getOperatImg() != null) { data.setOperatImgName(sysPictureBaseService.get(data.getOperatImg()).getName()); } return Result.ok(data); } @GetMapping("getImg") @ApiOperation("信息") public void getImg(HttpServletResponse response, Long id) { xhProductModelService.getImg(response, id); } @GetMapping("getProductList") public Result> getProductList(Long shipId, Integer productType) { if(productType==2){ shipId =null; } List list = xhProductModelService.getProductList(shipId, productType - 1); if(productType == 5){ List list2 = xhProductModelService.getProductList(shipId, productType - 2); list.addAll(list2); } return Result.ok(list); } @GetMapping("getTaskProductList") public Result> getTaskProductList() { List list = xhProductModelService.getTaskProductList(); return Result.ok(list); } @PostMapping("importProductExcel") @ApiOperation("导入产品模型") @LogOperation("导入产品模型") public Result importProductExcel(MultipartFile file, String progressId, Long pid) { Result> result = Result.ok(); try { List> importResults = xhProductModelService.importProductExcel(file, progressId, pid); StringBuilder str = new StringBuilder(); ImportUtil.importResult(result, importResults, str); ImportUtil.ImportErrResult(result, importResults, str); } catch (Exception e) { e.printStackTrace(); } return result; } @GetMapping("exportData") @ApiOperation("导出产品模型") @LogOperation("导出产品模型") public Result exportDataExcel(HttpServletRequest request, HttpServletResponse response, Long shipId, String fileName) { xhProductModelService.exportDataExcel(request, response, shipId, fileName); return null; } @PostMapping @ApiOperation("新增") @LogOperation("新增") public Result insert(@RequestBody XhProductModel xhProductModel) { //效验数据 ValidatorUtils.validateEntity(xhProductModel, AddGroup.class, DefaultGroup.class); Integer no = xhProductModelService.getNo(xhProductModel.getPid(), xhProductModel.getProductType()); if (xhProductModel.getSort() == null || xhProductModel.getSort() < no) { xhProductModel.setSort(no + 1); } if (xhProductModel.getProductType().equals("2")) { Long id = UUIDUtil.generateId(); xhProductModel.setId(id); xhProductModel.setShipId(id); ParamData data = new ParamData(); data.setShipId(id); data.setProductId(id); paramDataService.insert(data); } xhProductModel.setNamePath(xhProductModel.getNamePath() + "," + xhProductModel.getName()); xhProductModelService.insert(xhProductModel); Map imgMap = new HashMap<>(); imgMap = (Map) CacheUtils.get("sysImgCache", "sysImgCache"); imgMap.put(xhProductModel.getId(), xhProductModel); return Result.ok(); } @PostMapping("get") public Result getSelect(@RequestBody List list) { for (XhProductModel xhProductModel : list) { xhProductModel.setSrcId(xhProductModel.getId()); xhProductModel.setId(null); xhProductModel.setSort(xhProductModel.getSort()); xhProductModel.setProductType(xhProductModel.getNodeType()); if (xhProductModel.getNamePath() == null) { xhProductModel.setNamePath(xhProductModel.getName()); } else { xhProductModel.setNamePath(xhProductModel.getNamePath() + "," + xhProductModel.getName()); } this.insert(xhProductModel); } return Result.ok(); } @PutMapping @ApiOperation("修改") @LogOperation("修改") public Result update(@RequestBody XhProductModel xhProductModel) { //效验数据 ValidatorUtils.validateEntity(xhProductModel, UpdateGroup.class, DefaultGroup.class); xhProductModelService.update(xhProductModel); Map imgMap = new HashMap<>(); imgMap = (Map) CacheUtils.get("sysImgCache", "sysImgCache"); imgMap.put(xhProductModel.getId(), xhProductModel); return Result.ok(); } @DeleteMapping @ApiOperation("删除") @LogOperation("删除") public Result delete(@RequestBody Long[] ids) { //效验数据 AssertUtils.isArrayEmpty(ids, "id"); this.deleteByProduct(ids); return Result.ok(); } private void deleteByProduct(Long[] ids) { Map imgMap = new HashMap<>(); imgMap = (Map) CacheUtils.get("sysImgCache", "sysImgCache"); for (Long id : ids) { Long[] list = xhProductModelService.getByPid(id); if (list.length > 0){ this.deleteByProduct(list); } imgMap.remove(id); xhProductModelService.deleteLogic(id); } } }