futian.liu
2023-12-09 b16483ae0dff952639e4b7e152f72dc32e662154
consum-base/src/main/java/com/consum/base/controller/LWhFormInventoryController.java
@@ -1,7 +1,11 @@
package com.consum.base.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.core.utils.PageUtil;
import com.consum.base.pojo.excel.InventoryExcelTemplate;
import com.consum.base.pojo.query.LWhFormInventoryQry;
import com.consum.base.pojo.request.FormInventoryParam;
import com.consum.base.pojo.request.LWhFormInventoryParam;
@@ -9,26 +13,31 @@
import com.consum.base.pojo.response.FormInventoryGoodsVO;
import com.consum.base.pojo.response.FormInventoryVO;
import com.consum.base.service.FinSysTenantUserServiceImpl;
import com.consum.base.service.LWhFormInventoryCoreService;
import com.consum.base.service.LWhFormInventoryServiceImpl;
import com.consum.base.service.LWhFormInventoryService;
import com.consum.model.po.FinSysTenantUser;
import com.consum.model.po.LWhFormInventory;
import com.iplatform.model.po.S_user_core;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.web.ResponseValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -43,11 +52,9 @@
public class LWhFormInventoryController extends BaseController {
    @Autowired
    private LWhFormInventoryServiceImpl lWhFormInventoryService;
    private LWhFormInventoryService lWhFormInventoryService;
    @Autowired
    private FinSysTenantUserServiceImpl finSysTenantUserService;
    @Autowired
    private LWhFormInventoryCoreService lWhFormInventoryCoreService;
    /**
@@ -60,7 +67,13 @@
        @ApiImplicitParam(name = "param", value = "盘点单信息", dataType = "FormInventoryParam")
    })
    @PostMapping("/add")
    public ResponseValue add(@RequestBody FormInventoryParam param) {
    public ResponseValue add() {
        FormInventoryParam param = CommonUtil.getObjFromReqBody(FormInventoryParam.class);
        FormInventoryParam formInventoryParam = new FormInventoryParam();
        CommonUtil.copyProperties(param, formInventoryParam);
        param = formInventoryParam;
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
@@ -73,7 +86,7 @@
        FinSysTenantUser monitorUserInfo = new FinSysTenantUser();
        monitorUserInfo.setId(param.getMonitorUserId());
        FinSysTenantUser monitorUser = finSysTenantUserService.get(monitorUserInfo);
        int result = this.lWhFormInventoryService.add(param, this.getSysInfo(), operatorUser, monitorUser);
        int result = lWhFormInventoryService.add(param, this.getSysInfo(), operatorUser, monitorUser);
        if (result > 0) {
            return ResponseValue.success();
        }
@@ -90,12 +103,17 @@
        @ApiImplicitParam(name = "param", value = "盘点条件", dataType = "LWhFormInventoryParam", required = true, paramType = "query")
    })
    @GetMapping("/list")
    public ResponseValue queryList(LWhFormInventoryQry param) {
    public ResponseValue queryList() {
        LWhFormInventoryQry param = CommonUtil.getObjFromReq(LWhFormInventoryQry.class);
        LWhFormInventoryQry param2 = new LWhFormInventoryQry();
        CommonUtil.copyProperties(param, param2);
        param = param2;
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        GenericPager<LWhFormInventory> pager = this.lWhFormInventoryService.queryList(param, sysInfo);
        GenericPager<LWhFormInventory> pager = lWhFormInventoryService.queryList(param, sysInfo);
        return ResponseValue.success(pager);
    }
@@ -113,10 +131,12 @@
        if (id == null) {
            return ResponseValue.error("参数不能为空");
        }
        FormInventoryVO formInventoryVO = this.lWhFormInventoryService.queryInventBaseGoodTemplate(id);
        //通过机构查询相关的模板信息
        FormInventoryVO formInventoryVO = lWhFormInventoryService.queryInventBaseGoodTemplate(id);
        this.lWhFormInventoryService.saveInventory(formInventoryVO, id);
        return ResponseValue.success(formInventoryVO);
        // 保存后返回记录信息
        FormInventoryVO result = lWhFormInventoryService.saveInventory(formInventoryVO, id);
        return ResponseValue.success(result);
    }
    /**
@@ -129,7 +149,12 @@
        @ApiImplicitParam(name = "param", value = "盘点单信息", dataType = "FormInventoryParam")
    })
    @PostMapping("/edit")
    public ResponseValue edit(@RequestBody FormInventoryParam param) {
    public ResponseValue edit() {
        FormInventoryParam param = CommonUtil.getObjFromReqBody(FormInventoryParam.class);
        FormInventoryParam formInventoryParam = new FormInventoryParam();
        CommonUtil.copyProperties(param, formInventoryParam);
        param = formInventoryParam;
        LWhFormInventory lWhFormInventory = lWhFormInventoryService.get(new LWhFormInventory(param.getId()));
        if (lWhFormInventory == null) {
            return ResponseValue.error("编辑失败!");
@@ -141,8 +166,18 @@
        if (num == 0) {
            return ResponseValue.error("编辑失败!");
        }
        ResponseValue add = this.add(param);
        if (add.getCode() == ResponseValue.CODE_SUCCESS) {
        //根据盘点人id查询盘点人
        FinSysTenantUser finSysTenantUser = new FinSysTenantUser();
        finSysTenantUser.setId(param.getOperatorUserId());
        FinSysTenantUser operatorUser = finSysTenantUserService.get(finSysTenantUser);
        //根据监盘人id查询监盘人
        FinSysTenantUser monitorUserInfo = new FinSysTenantUser();
        monitorUserInfo.setId(param.getMonitorUserId());
        FinSysTenantUser monitorUser = finSysTenantUserService.get(monitorUserInfo);
        int result = lWhFormInventoryService.add(param, this.getSysInfo(), operatorUser, monitorUser);
        if (result > 0) {
            return ResponseValue.success();
        }
@@ -188,12 +223,17 @@
        @ApiImplicitParam(name = "param", value = "盘点单信息", dataType = "LWhFormInventoryDto")
    })
    @PostMapping("/temporary/storage")
    public ResponseValue temporaryStorage(@RequestBody LWhFormInventoryParam dto) {
        if (dto == null) {
    public ResponseValue updateTemporaryStorage() {
        LWhFormInventoryParam param = CommonUtil.getObjFromReqBody(LWhFormInventoryParam.class);
        LWhFormInventoryParam formInventoryParam = new LWhFormInventoryParam();
        CommonUtil.copyProperties(param, formInventoryParam);
        param = formInventoryParam;
        if (param == null) {
            return ResponseValue.error("参数错误");
        }
        int num = this.lWhFormInventoryService.updateInventoryInfo(dto, 1);
        int num = lWhFormInventoryService.updateInventoryInfo(param, 1, null, null);
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("暂存失败!");
    }
@@ -208,18 +248,20 @@
        @ApiImplicitParam(name = "param", value = "盘点单信息", dataType = "LWhFormInventoryDto")
    })
    @PostMapping("/finish")
    public ResponseValue finishPd(@RequestBody LWhFormInventoryParam dto) {
        if (dto == null) {
    public ResponseValue updateFinishPd() {
        LWhFormInventoryParam param = CommonUtil.getObjFromReqBody(LWhFormInventoryParam.class);
        LWhFormInventoryParam formInventoryParam = new LWhFormInventoryParam();
        CommonUtil.copyProperties(param, formInventoryParam);
        param = formInventoryParam;
        if (param == null) {
            return ResponseValue.error("参数错误");
        }
        int num = this.lWhFormInventoryService.updateInventoryInfo(dto, 2);
        S_user_core currentUser = this.getCurrentUser();
        FinSysTenantUser sysInfo = this.getSysInfo();
        int num = lWhFormInventoryService.updateInventoryInfo(param, 2, currentUser, sysInfo);
        String inOutFormByInventoryId = lWhFormInventoryCoreService.createInOutFormByInventoryId(dto.getId(), currentUser, sysInfo);
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error(inOutFormByInventoryId);
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("盘点失败!");
    }
    /**
@@ -232,12 +274,17 @@
        @ApiImplicitParam(name = "param", value = "盘点条件", dataType = "LWhFormInventoryParam", paramType = "query")
    })
    @GetMapping("/list/PdDetail")
    public ResponseValue queryPdDetailList(LWhFormInventoryQry param) {
    public ResponseValue queryPdDetailList() {
        LWhFormInventoryQry param = CommonUtil.getObjFromReq(LWhFormInventoryQry.class);
        LWhFormInventoryQry param2 = new LWhFormInventoryQry();
        CommonUtil.copyProperties(param, param2);
        param = param2;
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        PageUtil<FormInventoryDetailVO> result = this.lWhFormInventoryService.queryPdDetailList(param, sysInfo);
        PageUtil<FormInventoryDetailVO> result = lWhFormInventoryService.queryPdDetailList(param, sysInfo);
        return ResponseValue.success(result);
    }
@@ -255,16 +302,48 @@
        LWhFormInventory lWhFormInventory = new LWhFormInventory();
        lWhFormInventory.setId(id);
        LWhFormInventory item = this.lWhFormInventoryService.get(lWhFormInventory);
        LWhFormInventory item = lWhFormInventoryService.get(lWhFormInventory);
        if (Objects.isNull(item)) {
            return ResponseValue.error("盘点单不存在");
        }
        BeanUtils.copyProperties(item, formInventoryVO);
        List<FormInventoryGoodsVO> formInventoryGoodsVOS = this.lWhFormInventoryService.selectDetailById(id);
        List<FormInventoryGoodsVO> formInventoryGoodsVOS = lWhFormInventoryService.selectDetailById(id);
        formInventoryVO.setFormInventoryGoodsList(formInventoryGoodsVOS);
        return ResponseValue.success(formInventoryVO);
    }
    @ApiOperation(value = "盘点单导出", notes = "盘点单导出")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "盘点单id", dataType = "Long", required = true, paramType = "query")
    })
    @GetMapping("/list/export")
    public void export(Long id, HttpServletResponse response) throws Exception {
        List<InventoryExcelTemplate> exportList = lWhFormInventoryService.getExportList(id);
        if (CollectionUtils.isEmpty(exportList)) {
            throw new RuntimeException("数据为空");
        }
        TemplateExportParams params = new TemplateExportParams("import/低值易耗品盘点表.xls");
        params.setHeadingStartRow(2);
        Optional<InventoryExcelTemplate> first = exportList.stream().findFirst();
        InventoryExcelTemplate inventoryExcelTemplate = first.get();
        Long createTime = inventoryExcelTemplate.getCreateTime();
        String operatorName = inventoryExcelTemplate.getOperatorName();
        String monitorName = inventoryExcelTemplate.getMonitorName();
        Long endTime = inventoryExcelTemplate.getEndTime();
        Map<String, Object> map = new HashMap<>();
        map.put("date", DateUtils.toShowDate(createTime));
        map.put("endDate", DateUtils.toShowDate(endTime));
        map.put("monitorName", monitorName);
        map.put("name", operatorName);
        Workbook workbook = ExcelExportUtil.exportExcel(params, InventoryExcelTemplate.class,
            exportList, map);
        downLoadExcel("低值易耗品盘点表", response, workbook);
    }
}