| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- package com.chinaitop.depot.agent.crk.controller;
- import java.net.URLEncoder;
- 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 com.alibaba.fastjson.JSON;
- import com.chinaitop.utils.HTTPUtils;
- 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<Map<String, Object>> getAgentQcList(Integer pageNum, Integer pageSize, Integer agentId, Integer agentDepotId,
- Integer storehouseId, Integer warehouseId, String businessType, Integer lspz, String orgid){
- Map<String,Object> 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<Map<String, Object>> list = agentQcService.getAgentQcList(map);
- PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(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<String, Object> saveAgent(String agentQcJson,Integer orgId) throws Exception {
- Map<String, Object> modelMap = new HashMap<String, Object>();
- // 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<String, Object> removeAgentQc(Integer id){
- Map<String, Object> 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<String, Object> 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<String>> list = new ArrayList<List<String>>();//该list为数据返回的list
- Map<String, Object> 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<String, Object> 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 String selectAgentHouseWareList(Integer orgId) throws Exception {
- Map<String, Object> paramMap = new HashMap<String, Object>();
- paramMap.put("orgId", orgId);
- List<Map<String, Object>> list = agentQcService.selectAgentHouseWareList(paramMap);
- String str = JSON.toJSONString(list);
- String dataList = URLEncoder.encode(str, "UTF-8");
- String url = "http://localhost:9026/crkRecord/queryQcCrkRecordData?datas="+dataList;
- String strResult = HTTPUtils.doGet(url);
- return strResult;
- }
- @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<String, Object> editQcCrkRecordData(String qcCrkRecordData, Integer orgId, String realName) {
- Map<String, Object> map = new HashMap<String, Object>();
- 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;
- }
- }
|