AgentQcController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package com.chinaitop.depot.agent.crk.controller;
  2. import java.util.ArrayList;
  3. import java.util.Date;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.annotation.Resource;
  8. import javax.servlet.http.HttpServletRequest;
  9. import org.springframework.http.MediaType;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import org.springframework.web.multipart.MultipartFile;
  14. import com.chinaitop.depot.agent.basic.model.BusinessAgentDepot;
  15. import com.chinaitop.depot.agent.basic.service.agentService;
  16. import com.chinaitop.depot.agent.bgz.service.BusinessAgentBgmxzService;
  17. import com.chinaitop.depot.agent.crk.model.BusinessAgentQc;
  18. import com.chinaitop.depot.agent.crk.service.agentQcService;
  19. import com.chinaitop.depot.utils.ImportServiceImpl;
  20. import com.chinaitop.utils.ParameterUtil;
  21. import com.fasterxml.jackson.databind.ObjectMapper;
  22. import com.github.pagehelper.PageHelper;
  23. import com.github.pagehelper.PageInfo;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiImplicitParam;
  26. import io.swagger.annotations.ApiImplicitParams;
  27. import io.swagger.annotations.ApiOperation;
  28. import net.sf.json.JSONArray;
  29. import net.sf.json.JSONObject;
  30. @RestController
  31. @RequestMapping(value = "/agentQc")
  32. @Api(description = "汽车出入库")
  33. public class AgentQcController {
  34. @Resource
  35. private agentQcService agentQcService;
  36. @Resource
  37. private agentService agentService;
  38. @Resource
  39. private ImportServiceImpl importService;
  40. @Resource
  41. private BusinessAgentBgmxzService bgmxzService;
  42. /**
  43. * 查询汽车出入库信息记录
  44. * @param pageNum
  45. * @param pageSize
  46. * @return
  47. */
  48. @RequestMapping(value = "/getAgentQcList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  49. @ApiOperation(value="汽车出入库信息", notes = "查询汽车出入库信息记录")
  50. @ApiImplicitParams({
  51. @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
  52. @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
  53. @ApiImplicitParam(name = "agentId", value = "代储点id", paramType = "query"),
  54. @ApiImplicitParam(name = "agentDepotId", value = "代储库id", paramType = "query"),
  55. @ApiImplicitParam(name = "storehouseId", value = "仓房id", paramType = "query"),
  56. @ApiImplicitParam(name = "warehouseId", value = "货位id", paramType = "query"),
  57. @ApiImplicitParam(name = "businessType", value = "业务类型", paramType = "query"),
  58. @ApiImplicitParam(name = "lspz", value = "粮食品种", paramType = "query"),
  59. @ApiImplicitParam(name = "orgid", value = "组织id", paramType = "query")
  60. })
  61. public PageInfo<Map<String, Object>> getAgentQcList(Integer pageNum, Integer pageSize, Integer agentId, Integer agentDepotId,
  62. Integer storehouseId, Integer warehouseId, String businessType, Integer lspz, String orgid){
  63. Map<String,Object> map = new HashMap<>();
  64. map.put("orgId",orgid);
  65. if(ParameterUtil.isnotnull(agentId)){
  66. map.put("agentId",agentId);
  67. }
  68. if(ParameterUtil.isnotnull(agentDepotId)){
  69. map.put("agentDepotId",agentDepotId);
  70. }
  71. if(ParameterUtil.isnotnull(storehouseId)){
  72. map.put("storehouseId",storehouseId);
  73. }
  74. if(ParameterUtil.isnotnull(warehouseId)){
  75. map.put("warehouseId",warehouseId);
  76. }
  77. if (ParameterUtil.isnotnull(businessType)) {
  78. if (businessType.equals("1")) {
  79. map.put("businessType","汽车入库");
  80. } else if (businessType.equals("3")) {
  81. map.put("businessType","汽车出库");
  82. }
  83. }
  84. if(ParameterUtil.isnotnull(lspz)){
  85. map.put("lspz",lspz);
  86. }
  87. PageHelper.startPage(pageNum, pageSize);
  88. List<Map<String, Object>> list = agentQcService.getAgentQcList(map);
  89. PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(list);
  90. //处理驼峰命名大写问题
  91. List<Map<String, Object>> page_list = ParameterUtil.slashCapitals(pageInfo.getList());
  92. pageInfo.setList(page_list);
  93. return pageInfo;
  94. }
  95. /**
  96. * 保存汽车出入库信息
  97. * @param agentQcJson 主键id
  98. * @return
  99. * @throws Exception
  100. */
  101. @RequestMapping(value="/saveAgent", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  102. @ApiOperation(value="保存汽车出入库", notes = "保存汽车出入库信息")
  103. @ApiImplicitParams({
  104. @ApiImplicitParam(name = "agentQcJson", value = "汽车出入库信息", paramType = "form")
  105. })
  106. public Map<String, Object> saveAgent(String agentQcJson,Integer orgId) throws Exception {
  107. Map<String, Object> modelMap = new HashMap<String, Object>();
  108. // JSON字符串转对象
  109. ObjectMapper mapper = new ObjectMapper();
  110. BusinessAgentQc agent = (BusinessAgentQc)mapper.readValue(agentQcJson, BusinessAgentQc.class);
  111. if (ParameterUtil.isnull(agent.getId())) {
  112. agent.setOrgId(orgId);
  113. agent.setCreateTime(ParameterUtil.string2date(ParameterUtil.getSysDateTime()));//创建时间
  114. agentQcService.add(agent);
  115. } else {
  116. agentQcService.update(agent);
  117. }
  118. modelMap.put("agentId", agent.getId());
  119. modelMap.put("status", "success");
  120. return modelMap;
  121. }
  122. /**
  123. * 删除汽车出入库信息
  124. * @param id 主键id
  125. * @return
  126. */
  127. @RequestMapping(value="/removeAgentQc", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  128. @ApiOperation(value="删除汽车出入库信息", notes = "删除汽车出入库信息")
  129. @ApiImplicitParams({
  130. @ApiImplicitParam(name = "id", value = "汽车出入库主键id", paramType = "form")
  131. })
  132. public Map<String, Object> removeAgentQc(Integer id){
  133. Map<String, Object> modelMap = new HashMap<>();
  134. if (id != null) {
  135. agentQcService.updateDeleteById(id);
  136. modelMap.put("status", "success");
  137. }
  138. return modelMap;
  139. }
  140. /**
  141. * 根据id查找汽车出入库信息
  142. * @param id 主键id
  143. * @return
  144. */
  145. @RequestMapping(value="/getAgentQcEdit", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  146. @ApiOperation(value="根据id查找汽车出入库信息", notes = "根据id查找汽车出入库信息")
  147. @ApiImplicitParams({
  148. @ApiImplicitParam(name = "id", value = "汽车出入库主键id", paramType = "query")
  149. })
  150. public BusinessAgentQc getAgentQcEdit(Integer id) {
  151. BusinessAgentQc agent = new BusinessAgentQc();
  152. if (id != null) {
  153. agent = agentQcService.findById(id);
  154. }
  155. return agent;
  156. }
  157. /**
  158. * 导入excel
  159. * @param file 文件
  160. * @param fileType 类型:如xlsx
  161. * @param orgId 组织机构id
  162. * @return
  163. */
  164. @RequestMapping(value="/importFile", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  165. @ApiOperation(value="导入excel", notes = "导入excel")
  166. @ApiImplicitParams({
  167. @ApiImplicitParam(name = "file", value = "文件数据", paramType = "query"),
  168. @ApiImplicitParam(name = "fileType", value = "文件名", paramType = "query"),
  169. @ApiImplicitParam(name = "rootPath", value = "路径", paramType = "query"),
  170. @ApiImplicitParam(name = "orgId", value = "组织机构id", paramType = "query")
  171. })
  172. public Map<String, Object> importFile(MultipartFile file, String fileType, HttpServletRequest request, Integer orgId){
  173. String[] titleArr = {"通知单编号", "业务单号", "汽车牌号", "业务类型", "粮油品种",
  174. "数量(公斤)", "仓房名称", "货位名称", "出入库日期"};//第一行的title
  175. boolean[] emptyArr = {false, false, false, false, false,
  176. false, false, false, false};//指定列可为空,不可为空值为false.
  177. List<List<String>> list = new ArrayList<List<String>>();//该list为数据返回的list
  178. Map<String, Object> fileMap = new HashMap<>();
  179. String errormsg = null;
  180. try {
  181. errormsg = importService.importFile(file, fileType, request, titleArr, emptyArr, list,1);
  182. if (errormsg != null && !"".equals(errormsg)) {
  183. fileMap.put("errormsg",errormsg);
  184. return fileMap;
  185. }
  186. //查询代储点名称和代储库名称对应的id
  187. Map<String, Object> agentMap = agentService.getNameId(importService.nameData(file, fileType, request));
  188. if(ParameterUtil.isnull(agentMap)){
  189. fileMap.put("errormsg","代储点与代储库无关联,请查询后添加!");
  190. return fileMap;
  191. }
  192. if (list.size()>0) {
  193. errormsg = agentQcService.importData(list, orgId, agentMap);
  194. }
  195. } catch (Exception e) {
  196. e.printStackTrace();
  197. }
  198. fileMap.put("errormsg",errormsg);
  199. return fileMap;
  200. }
  201. @RequestMapping(value="/selectAgentHouseWareList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  202. @ApiOperation(value="查询代储库正常使用的货位数据信息", notes = "查询代储库正常使用的货位数据信息")
  203. @ApiImplicitParams({
  204. @ApiImplicitParam(name="orgId", value="当前单位ID", paramType="query")
  205. })
  206. public List<Map<String, Object>> selectAgentHouseWareList(Integer orgId) {
  207. Map<String, Object> paramMap = new HashMap<String, Object>();
  208. paramMap.put("orgId", orgId);
  209. List<Map<String, Object>> list = agentQcService.selectAgentHouseWareList(paramMap);
  210. return list;
  211. }
  212. @RequestMapping(value="/editQcCrkRecordData", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  213. @ApiOperation(value="同步功能", notes = "把出入库拿来的汽车出入库记录数据插入到代储库业务的汽车出入库记录表中")
  214. @ApiImplicitParams({
  215. @ApiImplicitParam(name="qcCrkRecordData", value="汽车出入库记录数据", paramType="form"),
  216. @ApiImplicitParam(name="orgId", value="当前单位ID", paramType="form"),
  217. @ApiImplicitParam(name="realName", value="当前操作人", paramType="form")
  218. })
  219. public Map<String, Object> editQcCrkRecordData(String qcCrkRecordData, Integer orgId, String realName) {
  220. Map<String, Object> map = new HashMap<String, Object>();
  221. try {
  222. JSONArray json = JSONArray.fromObject(qcCrkRecordData);
  223. if (json.size() > 0) {
  224. BusinessAgentQc agentQc = null;
  225. for (int i = 0; i < json.size(); i++) {
  226. JSONObject job = json.getJSONObject(i);
  227. Integer unitId = Integer.parseInt(job.get("unitid")+"");
  228. BusinessAgentDepot agentDepot = bgmxzService.selectAgentDepotObj(orgId, unitId);
  229. Integer agentDepotId = agentDepot.getId();
  230. Integer agentId = Integer.parseInt(agentDepot.getAgentId());
  231. Integer houseId = Integer.parseInt(job.get("houseId")+"");
  232. Integer wareId = Integer.parseInt(job.get("wareId")+"");
  233. agentQc = new BusinessAgentQc();
  234. agentQc.setOrgId(orgId);
  235. agentQc.setAgentId(agentId);
  236. agentQc.setAgentDepotId(agentDepotId);
  237. agentQc.setNotice(job.get("tzdbh")+"");
  238. agentQc.setBusinessNumber(job.get("bizNo")+"");
  239. agentQc.setCarBrand(job.get("cphm")+"");
  240. String businessType = job.get("ywlx")+"";
  241. if ("入仓".equals(businessType)) {
  242. businessType = "汽车入库";
  243. } else {
  244. businessType = "汽车出库";
  245. }
  246. agentQc.setBusinessType(businessType);
  247. agentQc.setLspz(Integer.parseInt(job.get("lspzid")+""));
  248. agentQc.setGrainNumber(job.get("count")+"");
  249. agentQc.setStorehouseId(houseId);
  250. agentQc.setWarehouseId(wareId);
  251. Date crk_time = ParameterUtil.string2date(job.get("rq")+"");
  252. agentQc.setCrkTime(crk_time);
  253. agentQc.setCreateTime(new Date());
  254. agentQc.setSjly(1);
  255. //插入代储点的库存实物表
  256. agentQcService.add(agentQc);
  257. }
  258. //修改代储点货位表的汽车出入库最后同步时间
  259. agentQcService.updateAgentDepot(orgId);
  260. }
  261. map.put("status", "200");
  262. map.put("msg", "操作成功!");
  263. } catch (NumberFormatException e) {
  264. map.put("msg", "操作失败!");
  265. e.printStackTrace();
  266. }
  267. return map;
  268. }
  269. }