cy
2023-12-01 ed7d7e411534f3bcc649f681aa8c529672b31e89
consum-base/src/main/java/com/consum/base/service/DepFormScrappedServiceImpl.java
@@ -8,7 +8,9 @@
import com.consum.base.pojo.DepFormScrappedModelParam;
import com.consum.base.pojo.LDeptFormScrappedParam;
import com.consum.base.pojo.query.LDeptFormScrappedQry;
import com.consum.base.pojo.response.DepFormScrappedExtendVo;
import com.consum.model.po.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iplatform.model.po.S_user_core;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.CollectionUtils;
@@ -17,6 +19,7 @@
import com.walker.infrastructure.utils.StringUtils;
import com.walker.jdbc.service.BaseServiceImpl;
import com.walker.web.ResponseValue;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -187,7 +190,7 @@
    /**
     * @Description 列表查询
     */
    private static String QUERY_LIST = "SELECT scrap.id,scrap.BUSINESS_FORM_CODE,scrap.DEPARTMENT_NAME,scrap.OPERATOR_NAME,scrap.DEAL_TIME,model.BASE_GOODS_TEMPLATE_ID,model.BASE_GOODS_TEMPLATE_NAME,SUM(model.COUNTS) total_Count FROM DEP_FORM_SCRAPPED scrap LEFT JOIN DEP_FORM_SCRAPPED_MODEL model ON scrap.id=model.DEP_FORM_SCRAPPED_ID where 1=1";
    private static String QUERY_LIST = "SELECT scrap.id,scrap.BUSINESS_FORM_CODE,scrap.AGENCY_NAME,scrap.DEPARTMENT_NAME,scrap.OPERATOR_NAME,scrap.DEAL_TIME,model.BASE_GOODS_TEMPLATE_ID,model.BASE_GOODS_TEMPLATE_NAME,SUM(model.COUNTS) total_Count,model.unit FROM DEP_FORM_SCRAPPED scrap LEFT JOIN DEP_FORM_SCRAPPED_MODEL model ON scrap.id=model.DEP_FORM_SCRAPPED_ID where 1=1";
    private static String QUERY_LIST_END = " GROUP BY scrap.id,scrap.BUSINESS_FORM_CODE,scrap.DEPARTMENT_NAME,scrap.OPERATOR_NAME,scrap.DEAL_TIME,model.BASE_GOODS_TEMPLATE_ID,model.BASE_GOODS_TEMPLATE_NAME ORDER BY scrap.DEAL_TIME DESC";
    public GenericPager<Map<String, Object>> queryList(LDeptFormScrappedQry param) {
@@ -225,4 +228,54 @@
        sql.append(QUERY_LIST_END);
        return selectSplit(sql.toString(), paramts, param.getPageNum(), param.getPageSize(), new MapperUtil());
    }
    /**
     * @Description 根据id查询详情
     */
    public DepFormScrappedExtendVo getById(Long id) {
        DepFormScrappedExtendVo scrappedExtend = new DepFormScrappedExtendVo();
        //1.查询报废单
        DepFormScrapped lWhFormScrapped = this.get(new DepFormScrapped(id));
        if (lWhFormScrapped != null) {
            BeanUtils.copyProperties(lWhFormScrapped, scrappedExtend);
        }
        ObjectMapper objectMapper = new ObjectMapper();
        //2.查询报废单物品
        DepFormScrappedGoods goodsQuery = new DepFormScrappedGoods();
        List<DepFormScrappedGoods> formScrappedGoodsList = select(goodsQuery);
        List<Map> goodsList = new ArrayList<>();
        for (DepFormScrappedGoods scrappedGoods : formScrappedGoodsList) {
            Map<String, Object> scrappedGoodsMap = objectMapper.convertValue(scrappedGoods, Map.class);
            // 查询规格型号
            Long scrappedGoodsId = scrappedGoods.getId();
            DepFormScrappedModel depFormScrappedModel = new DepFormScrappedModel();
            depFormScrappedModel.setDepFormScrappedGoodsId(scrappedGoodsId);
            List<DepFormScrappedModel> scrappedModelList = select(depFormScrappedModel);
            scrappedGoodsMap.put("models", scrappedModelList);
            goodsList.add(scrappedGoodsMap);
        }
        scrappedExtend.setGoods(goodsList);
        return scrappedExtend;
    }
    private static String EXPORT_SQL = "SELECT scrap.BUSINESS_FORM_CODE,scrap.DEAL_TIME,scrap.OPERATOR_NAME,scrap.AGENCY_NAME,model.BASE_GOODS_TEMPLATE_NAME,model.BASE_GOODS_MODELS_NAME,scrap.OUT_WAREHOUSE_NAME,model.COUNTS,2 AS TOTAL_PRICE,model.SCRAPPED_NAME,NULL AS bz FROM DEP_FORM_SCRAPPED scrap LEFT JOIN DEP_FORM_SCRAPPED_MODEL model ON scrap.id=model.DEP_FORM_SCRAPPED_ID WHERE 1=1 ";
    private static String EXPORT_SQL_END = "order by scrap.BUSINESS_FORM_CODE desc ";
    public List<Map<String, Object>> export(Long id, String agencyId) {
        HashMap<String, Object> paramts = new HashMap<>();
        StringBuilder sql = new StringBuilder(EXPORT_SQL);
        //报废单号
        if (id != null) {
            sql.append(" and scrap.id = :id");
            paramts.put("id", id);
        }
        //机构
        sql.append(" and scrap.AGENCY_ID = :agencyId ");
        if (agencyId != null) {
            paramts.put("agencyId", agencyId);
        }
        return select(sql.append(EXPORT_SQL_END).toString(), paramts, new MapperUtil());
    }
}