package com.chinaitop.depot.business.controller; import com.chinaitop.depot.business.model.BusinessDeliveryStorageNotice; import com.chinaitop.depot.business.model.BusinessStoreWareDetail; import com.chinaitop.depot.business.model.enums.AuditType; import com.chinaitop.depot.business.model.enums.StoreWareType; import com.chinaitop.depot.business.model.vo.BusinessDeliveryStorageNoticeAuditVO; import com.chinaitop.depot.business.service.BusinessDeliveryStorageNoticeService; import com.chinaitop.depot.business.service.BusinessStoreWareDetailService; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; 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 org.apache.commons.lang3.StringUtils; 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 javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 粮库业务管理-出入库通知单管理 *

Title: BusinessDeliveryStorageNoticeController

*

Description:

* @author yaoyabin * @date 2017年10月25日 下午5:36:15 */ @RestController @RequestMapping(value="/depot/business/deliveryStorageNotice") @Api(value= "BusinessDeliveryStorageNoticeController", description = "出入库通知单管理") public class BusinessDeliveryStorageNoticeController { @Resource private BusinessDeliveryStorageNoticeService deliveryStorageNoticeService; @Resource private BusinessStoreWareDetailService businessStoreWareDetailService; /* @Resource private BasicCodeRuleService basicCodeRuleService;*/ /** * 申请列表. * @param pageNum 页码 * @param pageSize 每页显示条数 * @return */ @RequestMapping(value="/getList", 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 = "userId", value = "当前登录人id", paramType = "query") }) public PageInfo getList(Integer pageNum, Integer pageSize, HttpServletRequest request, BusinessDeliveryStorageNotice notice,Integer userId) { /*UserInfo userInfo= (UserInfo) request.getSession().getAttribute("userInfo"); Integer userId = userInfo.getUserId();*/ List list = deliveryStorageNoticeService.queryByExample(pageNum, pageSize, userId, notice, "FIELD(audit_state,0,3,1,2,4 ), id desc"); PageInfo pageInfo = new PageInfo(list); return pageInfo; } //中转 /** * 申请列表. * @param pageNum 页码 * @param pageSize 每页显示条数 * @return */ @RequestMapping(value="/getListTransfer", 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 = "userId", value = "当前登录人id", paramType = "query") }) public PageInfo getListTransfer(Integer pageNum, Integer pageSize, HttpServletRequest request, BusinessDeliveryStorageNotice notice,Integer userId) { /*UserInfo userInfo= (UserInfo) request.getSession().getAttribute("userInfo"); Integer userId = userInfo.getUserId();*/ List list = deliveryStorageNoticeService.queryByExampleTransfer(pageNum, pageSize, userId, notice, "FIELD(audit_state,0,3,1,2,4 ), id desc"); PageInfo pageInfo = new PageInfo(list); return pageInfo; } /** * 审批通过列表. * @param pageNum 页码 * @param pageSize 每页显示条数 * @return */ @RequestMapping(value="/getAuditPassList", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET) @ApiOperation(value="通知单审批通过列表", notes = "查询数据列表,支持分页") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query") }) public PageInfo getAuditPassList(Integer pageNum, Integer pageSize, BusinessDeliveryStorageNotice notice) { notice.setAuditState(AuditType.AGREE.getAuditCode()); List list = deliveryStorageNoticeService.queryByExample(pageNum, pageSize, null, notice, "agree_time desc"); PageInfo pageInfo = new PageInfo(list); return pageInfo; } /** * 获取进度列表. * @param pageNum * @param pageSize * @param deliveryStorageNotice * @return */ @RequestMapping(value="/getScheduleList",produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET) @ApiOperation(value="获取通知单进度列表", notes = "查询数据列表,支持分页") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query") }) public PageInfo getScheduleList(Integer pageNum, Integer pageSize, BusinessDeliveryStorageNotice deliveryStorageNotice) { PageInfo pageInfo = deliveryStorageNoticeService.getScheduleList(pageNum, pageSize, deliveryStorageNotice); return pageInfo; } /** * 根据id查询. * @param id 主键 * @return */ @RequestMapping(value="/edit", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.GET) @ApiOperation(value="根据id查找", notes = "根据id查找") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "通知单id", paramType = "query") }) public Map edit(Integer id) { Map modelMap = new HashMap(); if (id != null) { BusinessDeliveryStorageNotice deliveryStorageNotice = deliveryStorageNoticeService.findById(id); modelMap.put("deliveryStorageNotice", deliveryStorageNotice); List list = new ArrayList(); Integer plan_id = deliveryStorageNotice.getPlanBid(); //计划ID Integer contract_id = deliveryStorageNotice.getContractBid(); //合同ID Map param_map = new HashMap(); List> map = null; if (null != contract_id) { list = businessStoreWareDetailService.getByZidAndType(contract_id, "contract"); param_map.put("contract_id", contract_id); map = businessStoreWareDetailService.selectContractUseCount(param_map); } else if (null != plan_id) { list = businessStoreWareDetailService.getByZidAndType(plan_id, "plan"); param_map.put("plan_id", plan_id); map = businessStoreWareDetailService.selectPlanUseCount(param_map); } BusinessStoreWareDetail obj = null; double sysl = 0d; double sum_use_num = 0d; //已使用总量 double plan_sum_num = 0d; //原计划数量 for (int i = 0; i < list.size(); i++) { obj = list.get(i); for (Map m : map) { if (obj.getHouseId().equals(m.get("house_id")) && obj.getWarehouseId().equals(m.get("warehouse_id"))) { if ("1".equals(deliveryStorageNotice.getBillType())) { plan_sum_num = Double.parseDouble(obj.getInCount()); sum_use_num = Double.parseDouble(m.get("in_count")+""); if (sum_use_num <= plan_sum_num) { sysl = plan_sum_num - sum_use_num; obj.setRemainingNumber(sysl+""); //页面上明细列表的剩余数量 } else if (sum_use_num > plan_sum_num){ sysl = sum_use_num - plan_sum_num; obj.setRemainingNumber("超出:"+sysl); } } if ("3".equals(deliveryStorageNotice.getBillType())) { plan_sum_num = Double.parseDouble(obj.getOutCount()); sum_use_num = Double.parseDouble(m.get("out_count")+""); if (sum_use_num <= plan_sum_num) { sysl = plan_sum_num - sum_use_num; obj.setOutRemainingNumber(sysl+""); //页面上明细列表的剩余数量 } else if (sum_use_num > plan_sum_num){ sysl = sum_use_num - plan_sum_num; obj.setOutRemainingNumber("超出:"+sysl); } } } } } //明细 List transferNoticeList= businessStoreWareDetailService.getByZidAndType(id, StoreWareType.transferNotice.getValue()); /*for (int i = 0; i < list.size(); i++) { obj = list.get(i); for (BusinessStoreWareDetail m : transferNoticeList) { if (obj.getHouseId().equals(m.getHouseId()) && obj.getWarehouseId().equals(m.getWarehouseId())) { if ("1".equals(deliveryStorageNotice.getBillType())) { m.setRemainingNumber(obj.getRemainingNumber()); } if ("3".equals(deliveryStorageNotice.getBillType())) { m.setOutRemainingNumber(obj.getOutRemainingNumber()); } } } }*/ List noticelList= businessStoreWareDetailService.getByZidAndType(id, StoreWareType.notice.getValue()); for (int i = 0; i < list.size(); i++) { obj = list.get(i); for (BusinessStoreWareDetail m : noticelList) { if (obj.getHouseId().equals(m.getHouseId()) && obj.getWarehouseId().equals(m.getWarehouseId())) { if ("1".equals(deliveryStorageNotice.getBillType())) { m.setRemainingNumber(obj.getRemainingNumber()); } if ("3".equals(deliveryStorageNotice.getBillType())) { m.setOutRemainingNumber(obj.getOutRemainingNumber()); } } } } if(transferNoticeList.size()>0 && transferNoticeList!=null){ modelMap.put("storeWareDetailList", transferNoticeList); } if(noticelList.size()>0 && noticelList!=null){ modelMap.put("storeWareDetailList", noticelList); } } return modelMap; } /** * 保存 * @param deliveryStorageNoticeJson 主表信息 * @param businessStoreWareDetailJson 明细 * @return * @throws JsonParseException * @throws JsonMappingException * @throws IOException */ @RequestMapping(value="/save", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST) @ApiOperation(value="保存数据", notes = "保存") @SuppressWarnings("unchecked") @ApiImplicitParams({ @ApiImplicitParam(name = "deliveryStorageNoticeJson", value = "主表数据", paramType = "query"), @ApiImplicitParam(name = "businessStoreWareDetailJson", value = "子表数据", paramType = "query"), @ApiImplicitParam(name = "userId", value = "当前登录人id", paramType = "query"), @ApiImplicitParam(name = "name", value = "当前登录人name", paramType = "query"), @ApiImplicitParam(name = "orgId", value = "当前登录人所在组织", paramType = "query"), @ApiImplicitParam(name = "depotInfoOrgId", value = "当前登录人所在组织id", paramType = "query") }) public Map save(String deliveryStorageNoticeJson, String businessStoreWareDetailJson, Integer userId, String name ,Integer orgId,Integer depotInfoOrgId,HttpServletRequest request) throws JsonParseException, JsonMappingException, IOException { Map modelMap = new HashMap(); /*UserInfo userInfo= (UserInfo) request.getSession().getAttribute("userInfo"); OrgInfo depotInfo = (OrgInfo)request.getSession().getAttribute("depotInfo");*/ try { // JSON字符串转对象 ObjectMapper mapper = new ObjectMapper(); BusinessDeliveryStorageNotice businessDeliveryStorageNotice = (BusinessDeliveryStorageNotice)mapper.readValue(deliveryStorageNoticeJson, BusinessDeliveryStorageNotice.class); List storeWareDetailList = null; if (businessStoreWareDetailJson != null) { storeWareDetailList = (List)mapper.readValue(businessStoreWareDetailJson, new TypeReference>(){}); //通知单的明细 库点名称都是一样的,所以取第一个 if(storeWareDetailList.get(0).getState() != storeWareDetailList.get(0).getOrgId()){ //代储库的 businessDeliveryStorageNotice.setHouseId(storeWareDetailList.get(0).getState()); }else{ businessDeliveryStorageNotice.setHouseId(storeWareDetailList.get(0).getOrgId()); } } if (businessDeliveryStorageNotice.getId() == null) { Map returnMap = deliveryStorageNoticeService.add(businessDeliveryStorageNotice, storeWareDetailList, userId, name , orgId, depotInfoOrgId); if (returnMap != null && returnMap.get("error") != null) { modelMap.put("status", "error"); modelMap.put("msg", returnMap.get("error")); return modelMap; } modelMap.put("id", returnMap.get("id")); } else { deliveryStorageNoticeService.update(businessDeliveryStorageNotice, storeWareDetailList); } modelMap.put("status", "success"); } catch (Exception e) { e.printStackTrace(); modelMap.put("status", "error"); modelMap.put("msg", "保存失败!"); return modelMap; } return modelMap; } /** * 删除(同时删除流程) * @param id 主键 * @param processInstanceId 流程实例id * @param deleteReason 删除原因 * @return * @throws JsonParseException * @throws JsonMappingException * @throws IOException */ @RequestMapping(value="/remove", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST) @ApiOperation(value="通知单删除(同时删除流程)", notes = "删除.") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键id", paramType = "query"), @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", paramType = "query"), @ApiImplicitParam(name = "deleteReason", value = "删除原因", paramType = "query"), @ApiImplicitParam(name = "planBid", value = "计划id", paramType = "query"), @ApiImplicitParam(name = "contractBid", value = "合同id", paramType = "query") }) public Map remove(Integer id, String processInstanceId, String deleteReason,Integer planBid,Integer contractBid) throws JsonParseException, JsonMappingException, IOException { Map modelMap = new HashMap(); if (id != null) { deliveryStorageNoticeService.remove(id, processInstanceId, deleteReason,planBid,contractBid); } modelMap.put("status", "success"); return modelMap; } /** * 提交 * @param businessDeliveryStorageNotice 业务主体 * @param assignee 下一个审批人 * @return */ @RequestMapping(value="/submit", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST) @ApiOperation(value="提交", notes = "提交") @ApiImplicitParams({ @ApiImplicitParam(name = "businessDeliveryStorageNotice", value = "业务主体", paramType = "query"), @ApiImplicitParam(name = "assignee", value = "下一个审批人", paramType = "query"), @ApiImplicitParam(name = "userId", value = "当前登录人id", paramType = "query"), @ApiImplicitParam(name = "realName", value = "当前登录人name", paramType = "query") }) public Map startProcess(BusinessDeliveryStorageNotice businessDeliveryStorageNotice, String assignee,Integer userId,String realName,HttpServletRequest request) { //UserInfo userInfo= (UserInfo) request.getSession().getAttribute("userInfo"); Map returnMap = deliveryStorageNoticeService.submit(businessDeliveryStorageNotice, assignee, userId, realName); return returnMap; } /** * 启用 * @param id 主键. * @return */ @RequestMapping(value="/application", produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST) @ApiOperation(value="通知单启用", notes = "启用.") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键id", paramType = "query") }) public Map application(Integer id) { Map modelMap = new HashMap(); Map returnMap = deliveryStorageNoticeService.application(id); if (StringUtils.isNoneBlank(returnMap.get("error"))) { modelMap.put("status", "error"); modelMap.put("msg", returnMap.get("error")); } else { modelMap.put("status", "success"); } return modelMap; } /** * 暂停 * @param id 主键. * @return */ @RequestMapping(value="/discontinue",produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST) @ApiOperation(value="通知单暂停", notes = "暂停.") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键id", paramType = "query") }) public Map discontinue(Integer id ,String refuseReason) { Map modelMap = new HashMap(); deliveryStorageNoticeService.discontinue(id,refuseReason); modelMap.put("status", "success"); return modelMap; } /** * 终止. * @param id 主键. * @return */ @RequestMapping(value="/finish",produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST) @ApiOperation(value="通知单终止", notes = "终止.") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键id", paramType = "query") }) public Map finish(Integer id,String refuseReason) { Map modelMap = new HashMap(); deliveryStorageNoticeService.finish(id,refuseReason); modelMap.put("status", "success"); return modelMap; } /** * 中转保存 * @param deliveryStorageNoticeJson 主表信息 * @param businessStoreWareDetailJson 明细 * @return * @throws JsonParseException * @throws JsonMappingException * @throws IOException */ @RequestMapping(value="/addTransfer",produces = MediaType.APPLICATION_JSON_VALUE, method=RequestMethod.POST) @ApiOperation(value="中转保存", notes = "保存") @SuppressWarnings("unchecked") @ApiImplicitParams({ @ApiImplicitParam(name = "deliveryStorageNoticeJson", value = "主表数据", paramType = "query"), @ApiImplicitParam(name = "businessStoreWareDetailJson", value = "子表数据", paramType = "query"), @ApiImplicitParam(name = "userId", value = "当前登录人id", paramType = "query"), @ApiImplicitParam(name = "name", value = "当前登录人name", paramType = "query"), @ApiImplicitParam(name = "orgId", value = "当前登录人所在组织", paramType = "query") }) public Map addTransfer(String deliveryStorageNoticeJson, String businessStoreWareDetailJson, Integer userId, String name ,Integer orgId,HttpServletRequest request) throws JsonParseException, JsonMappingException, IOException { Map modelMap = new HashMap(); /* UserInfo userInfo= (UserInfo) request.getSession().getAttribute("userInfo"); OrgInfo depotInfo = (OrgInfo)request.getSession().getAttribute("depotInfo");*/ try { // JSON字符串转对象 ObjectMapper mapper = new ObjectMapper(); BusinessDeliveryStorageNotice businessDeliveryStorageNotice = (BusinessDeliveryStorageNotice)mapper.readValue(deliveryStorageNoticeJson, BusinessDeliveryStorageNotice.class); businessDeliveryStorageNotice.setHouseId(orgId); //List storeWareDetailList = null; /*if (businessStoreWareDetailJson != null) { storeWareDetailList = (List)mapper.readValue(businessStoreWareDetailJson, new TypeReference>(){}); }*/ List storeWareDetailList = null; if (businessStoreWareDetailJson != null) { storeWareDetailList = (List)mapper.readValue(businessStoreWareDetailJson, new TypeReference>(){}); } if (businessDeliveryStorageNotice.getId() == null) { Map returnMap = deliveryStorageNoticeService.addTransfer(businessDeliveryStorageNotice, storeWareDetailList, userId, name , orgId); if (returnMap != null && returnMap.get("error") != null) { modelMap.put("status", "error"); modelMap.put("msg", returnMap.get("error")); return modelMap; } } else { //deliveryStorageNoticeService.update(businessDeliveryStorageNotice, storeWareDetailList); } modelMap.put("status", "success"); } catch (Exception e) { e.printStackTrace(); modelMap.put("status", "error"); modelMap.put("msg", "保存失败!"); return modelMap; } return modelMap; } }