package com.chinaitop.depot.agent.crk.controller; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import com.chinaitop.depot.agent.basic.model.BusinessAgentDepot; import com.chinaitop.depot.agent.basic.service.agentService; import com.chinaitop.depot.agent.bgz.service.BusinessAgentBgmxzService; import com.chinaitop.depot.agent.crk.model.BusinessAgentQc; import com.chinaitop.depot.agent.crk.service.agentQcService; import com.chinaitop.depot.utils.ImportServiceImpl; import com.chinaitop.utils.ParameterUtil; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @RestController @RequestMapping(value = "/agentQc") @Api(description = "汽车出入库") public class AgentQcController { @Resource private agentQcService agentQcService; @Resource private agentService agentService; @Resource private ImportServiceImpl importService; @Resource private BusinessAgentBgmxzService bgmxzService; /** * 查询汽车出入库信息记录 * @param pageNum * @param pageSize * @return */ @RequestMapping(value = "/getAgentQcList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) @ApiOperation(value="汽车出入库信息", notes = "查询汽车出入库信息记录") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"), @ApiImplicitParam(name = "agentId", value = "代储点id", paramType = "query"), @ApiImplicitParam(name = "agentDepotId", value = "代储库id", paramType = "query"), @ApiImplicitParam(name = "storehouseId", value = "仓房id", paramType = "query"), @ApiImplicitParam(name = "warehouseId", value = "货位id", paramType = "query"), @ApiImplicitParam(name = "businessType", value = "业务类型", paramType = "query"), @ApiImplicitParam(name = "lspz", value = "粮食品种", paramType = "query"), @ApiImplicitParam(name = "orgid", value = "组织id", paramType = "query") }) public PageInfo> getAgentQcList(Integer pageNum, Integer pageSize, Integer agentId, Integer agentDepotId, Integer storehouseId, Integer warehouseId, String businessType, Integer lspz, String orgid){ Map map = new HashMap<>(); map.put("orgId",orgid); if(ParameterUtil.isnotnull(agentId)){ map.put("agentId",agentId); } if(ParameterUtil.isnotnull(agentDepotId)){ map.put("agentDepotId",agentDepotId); } if(ParameterUtil.isnotnull(storehouseId)){ map.put("storehouseId",storehouseId); } if(ParameterUtil.isnotnull(warehouseId)){ map.put("warehouseId",warehouseId); } if (ParameterUtil.isnotnull(businessType)) { if (businessType.equals("1")) { map.put("businessType","汽车入库"); } else if (businessType.equals("3")) { map.put("businessType","汽车出库"); } } if(ParameterUtil.isnotnull(lspz)){ map.put("lspz",lspz); } PageHelper.startPage(pageNum, pageSize); List> list = agentQcService.getAgentQcList(map); PageInfo> pageInfo = new PageInfo>(list); //处理驼峰命名大写问题 List> page_list = ParameterUtil.slashCapitals(pageInfo.getList()); pageInfo.setList(page_list); return pageInfo; } /** * 保存汽车出入库信息 * @param agentQcJson 主键id * @return * @throws Exception */ @RequestMapping(value="/saveAgent", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST) @ApiOperation(value="保存汽车出入库", notes = "保存汽车出入库信息") @ApiImplicitParams({ @ApiImplicitParam(name = "agentQcJson", value = "汽车出入库信息", paramType = "form") }) public Map saveAgent(String agentQcJson,Integer orgId) throws Exception { Map modelMap = new HashMap(); // JSON字符串转对象 ObjectMapper mapper = new ObjectMapper(); BusinessAgentQc agent = (BusinessAgentQc)mapper.readValue(agentQcJson, BusinessAgentQc.class); if (ParameterUtil.isnull(agent.getId())) { agent.setOrgId(orgId); agent.setCreateTime(ParameterUtil.string2date(ParameterUtil.getSysDateTime()));//创建时间 agentQcService.add(agent); } else { agentQcService.update(agent); } modelMap.put("agentId", agent.getId()); modelMap.put("status", "success"); return modelMap; } /** * 删除汽车出入库信息 * @param id 主键id * @return */ @RequestMapping(value="/removeAgentQc", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST) @ApiOperation(value="删除汽车出入库信息", notes = "删除汽车出入库信息") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "汽车出入库主键id", paramType = "form") }) public Map removeAgentQc(Integer id){ Map modelMap = new HashMap<>(); if (id != null) { agentQcService.updateDeleteById(id); modelMap.put("status", "success"); } return modelMap; } /** * 根据id查找汽车出入库信息 * @param id 主键id * @return */ @RequestMapping(value="/getAgentQcEdit", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) @ApiOperation(value="根据id查找汽车出入库信息", notes = "根据id查找汽车出入库信息") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "汽车出入库主键id", paramType = "query") }) public BusinessAgentQc getAgentQcEdit(Integer id) { BusinessAgentQc agent = new BusinessAgentQc(); if (id != null) { agent = agentQcService.findById(id); } return agent; } /** * 导入excel * @param file 文件 * @param fileType 类型:如xlsx * @param orgId 组织机构id * @return */ @RequestMapping(value="/importFile", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST) @ApiOperation(value="导入excel", notes = "导入excel") @ApiImplicitParams({ @ApiImplicitParam(name = "file", value = "文件数据", paramType = "query"), @ApiImplicitParam(name = "fileType", value = "文件名", paramType = "query"), @ApiImplicitParam(name = "rootPath", value = "路径", paramType = "query"), @ApiImplicitParam(name = "orgId", value = "组织机构id", paramType = "query") }) public Map importFile(MultipartFile file, String fileType, HttpServletRequest request, Integer orgId){ String[] titleArr = {"通知单编号", "业务单号", "汽车牌号", "业务类型", "粮油品种", "数量(公斤)", "仓房名称", "货位名称", "出入库日期"};//第一行的title boolean[] emptyArr = {false, false, false, false, false, false, false, false, false};//指定列可为空,不可为空值为false. List> list = new ArrayList>();//该list为数据返回的list Map fileMap = new HashMap<>(); String errormsg = null; try { errormsg = importService.importFile(file, fileType, request, titleArr, emptyArr, list,1); if (errormsg != null && !"".equals(errormsg)) { fileMap.put("errormsg",errormsg); return fileMap; } //查询代储点名称和代储库名称对应的id Map agentMap = agentService.getNameId(importService.nameData(file, fileType, request)); if(ParameterUtil.isnull(agentMap)){ fileMap.put("errormsg","代储点与代储库无关联,请查询后添加!"); return fileMap; } if (list.size()>0) { errormsg = agentQcService.importData(list, orgId, agentMap); } } catch (Exception e) { e.printStackTrace(); } fileMap.put("errormsg",errormsg); return fileMap; } @RequestMapping(value="/selectAgentHouseWareList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) @ApiOperation(value="查询代储库正常使用的货位数据信息", notes = "查询代储库正常使用的货位数据信息") @ApiImplicitParams({ @ApiImplicitParam(name="orgId", value="当前单位ID", paramType="query") }) public List> selectAgentHouseWareList(Integer orgId) { Map paramMap = new HashMap(); paramMap.put("orgId", orgId); List> list = agentQcService.selectAgentHouseWareList(paramMap); return list; } @RequestMapping(value="/editQcCrkRecordData", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST) @ApiOperation(value="同步功能", notes = "把出入库拿来的汽车出入库记录数据插入到代储库业务的汽车出入库记录表中") @ApiImplicitParams({ @ApiImplicitParam(name="qcCrkRecordData", value="汽车出入库记录数据", paramType="form"), @ApiImplicitParam(name="orgId", value="当前单位ID", paramType="form"), @ApiImplicitParam(name="realName", value="当前操作人", paramType="form") }) public Map editQcCrkRecordData(String qcCrkRecordData, Integer orgId, String realName) { Map map = new HashMap(); try { JSONArray json = JSONArray.fromObject(qcCrkRecordData); if (json.size() > 0) { BusinessAgentQc agentQc = null; for (int i = 0; i < json.size(); i++) { JSONObject job = json.getJSONObject(i); Integer unitId = Integer.parseInt(job.get("unitid")+""); BusinessAgentDepot agentDepot = bgmxzService.selectAgentDepotObj(orgId, unitId); Integer agentDepotId = agentDepot.getId(); Integer agentId = Integer.parseInt(agentDepot.getAgentId()); Integer houseId = Integer.parseInt(job.get("houseId")+""); Integer wareId = Integer.parseInt(job.get("wareId")+""); agentQc = new BusinessAgentQc(); agentQc.setOrgId(orgId); agentQc.setAgentId(agentId); agentQc.setAgentDepotId(agentDepotId); agentQc.setNotice(job.get("tzdbh")+""); agentQc.setBusinessNumber(job.get("bizNo")+""); agentQc.setCarBrand(job.get("cphm")+""); String businessType = job.get("ywlx")+""; if ("入仓".equals(businessType)) { businessType = "汽车入库"; } else { businessType = "汽车出库"; } agentQc.setBusinessType(businessType); agentQc.setLspz(Integer.parseInt(job.get("lspzid")+"")); agentQc.setGrainNumber(job.get("count")+""); agentQc.setStorehouseId(houseId); agentQc.setWarehouseId(wareId); Date crk_time = ParameterUtil.string2date(job.get("rq")+""); agentQc.setCrkTime(crk_time); agentQc.setCreateTime(new Date()); agentQc.setSjly(1); //插入代储点的库存实物表 agentQcService.add(agentQc); } //修改代储点货位表的汽车出入库最后同步时间 agentQcService.updateAgentDepot(orgId); } map.put("status", "200"); map.put("msg", "操作成功!"); } catch (NumberFormatException e) { map.put("msg", "操作失败!"); e.printStackTrace(); } return map; } }