MaterialsUsingController.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. package cn.com.lzt.materialsusing.controller;
  2. import cn.com.lzt.arrangeduty.dao.UserOrgMinidao;
  3. import cn.com.lzt.goodsinfo.entity.TBGoodsInfoEntity;
  4. import cn.com.lzt.materialsusing.dao.MaterialsUsingDao;
  5. import cn.com.lzt.materialsusing.entity.MaterialsUsingEntity;
  6. import cn.com.lzt.materialsusing.page.MaterialsUsingPage;
  7. import cn.com.lzt.materialsusing.service.MaterialsUsingServiceI;
  8. import cn.com.lzt.materialsusingdetail.entity.MaterialsUsingDetailsEntity;
  9. import cn.com.lzt.priceinfo.entity.TBPriceInfoEntity;
  10. import cn.com.lzt.tools.OrderNumTools;
  11. import cn.com.lzt.warehouse.entity.WarehouseEntity;
  12. import org.apache.commons.lang.xwork.StringUtils;
  13. import org.apache.log4j.Logger;
  14. import org.jeecgframework.core.beanvalidator.BeanValidators;
  15. import org.jeecgframework.core.common.controller.BaseController;
  16. import org.jeecgframework.core.common.dao.ICommonDao;
  17. import org.jeecgframework.core.common.exception.BusinessException;
  18. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  19. import org.jeecgframework.core.common.model.json.AjaxJson;
  20. import org.jeecgframework.core.common.model.json.DataGrid;
  21. import org.jeecgframework.core.constant.Globals;
  22. import org.jeecgframework.core.util.*;
  23. import org.jeecgframework.tag.core.easyui.TagUtil;
  24. import org.jeecgframework.web.system.dao.JeecgDictDao;
  25. import org.jeecgframework.web.system.pojo.base.DictEntity;
  26. import org.jeecgframework.web.system.pojo.base.TSUser;
  27. import org.jeecgframework.web.system.service.SystemService;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.http.HttpHeaders;
  30. import org.springframework.http.HttpStatus;
  31. import org.springframework.http.MediaType;
  32. import org.springframework.http.ResponseEntity;
  33. import org.springframework.stereotype.Controller;
  34. import org.springframework.web.bind.annotation.*;
  35. import org.springframework.web.servlet.ModelAndView;
  36. import org.springframework.web.util.UriComponentsBuilder;
  37. import javax.servlet.http.HttpServletRequest;
  38. import javax.servlet.http.HttpServletResponse;
  39. import javax.servlet.http.HttpSession;
  40. import javax.validation.ConstraintViolation;
  41. import javax.validation.Validator;
  42. import java.net.URI;
  43. import java.text.SimpleDateFormat;
  44. import java.util.*;
  45. /**
  46. * @Title: Controller
  47. * @Description: 物料领用单
  48. * @author onlineGenerator
  49. * @date 2017-06-07 17:15:24
  50. * @version V1.0
  51. *
  52. */
  53. @Controller
  54. @RequestMapping("/materialsUsingController")
  55. public class MaterialsUsingController extends BaseController {
  56. /**
  57. * Logger for this class
  58. */
  59. private static final Logger logger = Logger.getLogger(MaterialsUsingController.class);
  60. @Autowired
  61. private MaterialsUsingServiceI mUsingService;
  62. @Autowired
  63. private SystemService systemService;
  64. @Autowired
  65. private Validator validator;
  66. @Autowired
  67. public ICommonDao commonDao = null;
  68. @Autowired
  69. private MaterialsUsingDao materialsUsingDao;
  70. @Autowired
  71. private JeecgDictDao jeecgDictDao;
  72. @Autowired
  73. private UserOrgMinidao userOrgdao;
  74. /**
  75. * 物料领用表列表 页面跳转
  76. *
  77. * @return
  78. */
  79. @RequestMapping(params = "list")
  80. public ModelAndView list(HttpServletRequest request) {
  81. ModelAndView mv = new ModelAndView("cn/com/lzt/materialsusing/materialsusingList");
  82. mv.addObject("userid", ResourceUtil.getSessionUser().getId());
  83. return mv;
  84. }
  85. @RequestMapping(params = "datagrid")
  86. public void datagrid(MaterialsUsingEntity materialsUsing,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  87. CriteriaQuery cq = new CriteriaQuery(MaterialsUsingEntity.class, dataGrid);
  88. String orderDateBegin = request.getParameter("orderDate_begin");
  89. String orderDateEnd = request.getParameter("orderDate_end");
  90. String orderOnumber = materialsUsing.getOrderOnumber();
  91. if(StringUtils.isNotBlank(orderOnumber)){
  92. materialsUsing.setOrderOnumber("*" +orderOnumber +"*");
  93. }
  94. //当前登录用户ID
  95. String userid = ResourceUtil.getSessionUser().getId();
  96. String hql1 = "from WarehouseEntity where responsiblePerson=? ";
  97. List<WarehouseEntity> warehouseList = systemService.findHql(hql1, userid);
  98. if(warehouseList.size() == 0)
  99. cq.eq("warehouseId","");
  100. else {
  101. List<String> wids = new ArrayList<String>();
  102. for(WarehouseEntity warehouse:warehouseList) {
  103. wids.add(warehouse.getId());
  104. }
  105. cq.in("warehouseId", wids.toArray());
  106. }
  107. //查询条件组装器
  108. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, materialsUsing);
  109. try{
  110. //自定义追加查询条件
  111. if(StringUtils.isNotBlank(orderDateBegin) && StringUtils.isNotBlank(orderDateEnd)){
  112. cq.ge("orderDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateBegin + " 00:00:00"));
  113. cq.le("orderDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateEnd + " 23:59:59"));
  114. }
  115. }catch (Exception e) {
  116. throw new BusinessException(e.getMessage());
  117. }
  118. cq.notEq("orderStatus", "-1");
  119. cq.add();
  120. String warehouseId = materialsUsing.getWarehouseId();
  121. if(StringUtils.isNotBlank(warehouseId)) {
  122. cq.eq("warehouseId", warehouseId);
  123. cq.add();
  124. }
  125. List<MaterialsUsingEntity> list = mUsingService.getListByCriteriaQuery(cq, false);
  126. dataGrid.setResults(list);
  127. // this.mUsingService.getDataGridReturn(cq, false);
  128. TagUtil.datagrid(response, dataGrid);
  129. }
  130. /**
  131. * 删除物料领用表
  132. *
  133. * @return
  134. */
  135. @RequestMapping(params = "doDel")
  136. @ResponseBody
  137. public AjaxJson doDel(String id, HttpServletRequest request) {
  138. MaterialsUsingEntity materialsUsing ;
  139. AjaxJson j = new AjaxJson();
  140. materialsUsing = systemService.getEntity(MaterialsUsingEntity.class, id);
  141. String message = "物料领用表删除成功";
  142. try{
  143. mUsingService.delMain(materialsUsing);
  144. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  145. }catch(Exception e){
  146. e.printStackTrace();
  147. message = "物料领用表删除失败";
  148. throw new BusinessException(e.getMessage());
  149. }
  150. j.setMsg(message);
  151. return j;
  152. }
  153. /**
  154. * 批量删除物料领用表
  155. *
  156. * @return
  157. */
  158. @RequestMapping(params = "doBatchDel")
  159. @ResponseBody
  160. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  161. AjaxJson j = new AjaxJson();
  162. String message = "物料领用表删除成功";
  163. try{
  164. for(String id:ids.split(",")){
  165. MaterialsUsingEntity materialsUsing = systemService.getEntity(MaterialsUsingEntity.class,
  166. id
  167. );
  168. mUsingService.delMain(materialsUsing);
  169. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  170. }
  171. }catch(Exception e){
  172. e.printStackTrace();
  173. message = "物料领用表删除失败";
  174. throw new BusinessException(e.getMessage());
  175. }
  176. j.setMsg(message);
  177. return j;
  178. }
  179. /**
  180. * 添加物料领用表
  181. *
  182. * @param ids
  183. * @return
  184. */
  185. @RequestMapping(params = "doAdd")
  186. @ResponseBody
  187. public AjaxJson doAdd(MaterialsUsingEntity materialsUsing,MaterialsUsingPage materialsUsingPage, HttpServletRequest request) {
  188. List<MaterialsUsingDetailsEntity> orderDetailsList = materialsUsingPage.getMaterialsUsingDetailsList();
  189. AjaxJson j = new AjaxJson();
  190. String message = "添加成功";
  191. try{
  192. // 设置单号
  193. materialsUsing.setOrderOnumber(OrderNumTools.generateNextBillCode(getMaxLocalCode(),"MU"));
  194. materialsUsing.setOrderStatus(Globals.UNAPPROVED);// 未审批状态
  195. mUsingService.addMain(materialsUsing, orderDetailsList);
  196. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  197. }catch(Exception e){
  198. e.printStackTrace();
  199. message = "物料领用表添加失败";
  200. throw new BusinessException(e.getMessage());
  201. }
  202. j.setMsg(message);
  203. return j;
  204. }
  205. private String getMaxLocalCode(){
  206. StringBuilder sb = new StringBuilder();
  207. sb.append("SELECT order_onumber FROM t_b_materialsusing");
  208. sb.append(" ORDER BY order_onumber DESC");
  209. List<Map<String, Object>> objMapList = systemService.findForJdbc(sb.toString(), 1, 1);
  210. String returnCode = null;
  211. if(objMapList!=null && objMapList.size()>0){
  212. returnCode = (String)objMapList.get(0).get("order_onumber");
  213. }
  214. return returnCode;
  215. }
  216. /**
  217. * 更新物料领用表
  218. *
  219. * @param ids
  220. * @return
  221. */
  222. @RequestMapping(params = "doUpdate")
  223. @ResponseBody
  224. public AjaxJson doUpdate(MaterialsUsingEntity materialsUsing,MaterialsUsingPage materialsUsingPage, HttpServletRequest request) {
  225. List<MaterialsUsingDetailsEntity> orderDetailsList = materialsUsingPage.getMaterialsUsingDetailsList();
  226. AjaxJson j = new AjaxJson();
  227. String message = "更新成功";
  228. try{
  229. mUsingService.updateMain(materialsUsing, orderDetailsList);
  230. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  231. }catch(Exception e){
  232. e.printStackTrace();
  233. message = "更新物料领用表失败";
  234. throw new BusinessException(e.getMessage());
  235. }
  236. j.setMsg(message);
  237. return j;
  238. }
  239. /**
  240. * 物料领用表新增页面跳转
  241. *
  242. * @return
  243. */
  244. @RequestMapping(params = "goAdd")
  245. public ModelAndView goAdd(MaterialsUsingEntity materialsUsing, HttpServletRequest req) {
  246. if (StringUtil.isNotEmpty(materialsUsing.getId())) {
  247. materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, materialsUsing.getId());
  248. req.setAttribute("materialsUsingPage", materialsUsing);
  249. }else {
  250. //当前登录用户ID
  251. String userid = ResourceUtil.getSessionUser().getId();
  252. String hql1 = "from WarehouseEntity where responsiblePerson=? ";
  253. List<WarehouseEntity> warehouseList = systemService.findHql(hql1, userid);
  254. if(warehouseList.size() > 0)
  255. {
  256. materialsUsing.setWarehouseId(warehouseList.get(0).getId());
  257. materialsUsing.setWarehouseName( warehouseList.get(0).getWarehouseName());
  258. }
  259. req.setAttribute("materialsUsingPage", materialsUsing);
  260. }
  261. return new ModelAndView("cn/com/lzt/materialsusing/materialsusing-add");
  262. }
  263. /**
  264. * 物料领用表编辑页面跳转
  265. *
  266. * @return
  267. */
  268. @RequestMapping(params = "goUpdate")
  269. public ModelAndView goUpdate(MaterialsUsingEntity materialsUsing, HttpServletRequest req) {
  270. String isView = req.getParameter("viewFlag");
  271. req.setAttribute("viewFlag", isView);
  272. if (StringUtil.isNotEmpty(materialsUsing.getId())) {
  273. materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, materialsUsing.getId());
  274. // idandname(req, materialsUsing);
  275. req.setAttribute("materialsUsingPage", materialsUsing);
  276. }
  277. return new ModelAndView("cn/com/lzt/materialsusing/materialsusing-update");
  278. }
  279. /**
  280. * 加载明细列表[物料领用商品]
  281. *
  282. * @return
  283. */
  284. @RequestMapping(params = "MaterialsUsingDetailsList")
  285. public ModelAndView orderDetailsList(MaterialsUsingEntity materialsUsing, HttpServletRequest req) {
  286. List<MaterialsUsingDetailsEntity> materialsUsingDetailsEntityList = new ArrayList<MaterialsUsingDetailsEntity>();
  287. //===================================================================================
  288. //获取参数
  289. Object id0 = materialsUsing.getId();
  290. //===================================================================================
  291. //查询-物料领用商品
  292. if(id0 == null || id0.toString().length()!= 32){
  293. //当前登录用户ID
  294. String userid = ResourceUtil.getSessionUser().getId();
  295. String warehouseid = req.getParameter("warehouseid");
  296. if(warehouseid == null || warehouseid.trim().length() == 0) {
  297. String hql1 = "from WarehouseEntity where responsiblePerson=? ";
  298. List<WarehouseEntity> warehouseList = systemService.findHql(hql1, userid);
  299. if(warehouseList.size() > 0){
  300. warehouseid = warehouseList.get(0).getId();
  301. }
  302. }
  303. //查询此仓库上次填报的物料领用单
  304. materialsUsingDetailsEntityList = materialsUsingDao.getDetails4NewBill(warehouseid);
  305. for(int i = 0 ;i < materialsUsingDetailsEntityList.size();i++){
  306. MaterialsUsingDetailsEntity materialsUsingDetailsEntity = materialsUsingDetailsEntityList.get(i);
  307. TBGoodsInfoEntity goodsInfoEntity = systemService.get(TBGoodsInfoEntity.class, materialsUsingDetailsEntity.getGoodsId());
  308. materialsUsingDetailsEntity.setMeasureUnit(goodsInfoEntity.getSalesUnit());
  309. }
  310. }else {
  311. String hql0 = "from MaterialsUsingDetailsEntity where 1 = 1 AND fK_ID =? ";
  312. try{
  313. materialsUsingDetailsEntityList = systemService.findHql(hql0,id0);
  314. }catch(Exception e){
  315. logger.info(e.getMessage());
  316. }
  317. }
  318. req.setAttribute("materialsUsingDetailsList", materialsUsingDetailsEntityList);
  319. return new ModelAndView("cn/com/lzt/materialsusingdetails/materialsusingDetailsList");
  320. }
  321. /**
  322. * 加载明细列表[物料领用商品]
  323. *
  324. * @return
  325. */
  326. @RequestMapping(params = "OnhandReportInitialDetailsList")
  327. public ModelAndView OnhandReportInitialDetailsList(MaterialsUsingEntity materialsUsing, HttpServletRequest req) {
  328. List<MaterialsUsingDetailsEntity> orderDetailsEntityList = new ArrayList<MaterialsUsingDetailsEntity>();
  329. //===================================================================================
  330. //获取参数
  331. Object id0 = materialsUsing.getId();
  332. //===================================================================================
  333. //查询-物料领用商品
  334. if(id0 == null || id0.toString().length()!= 32)
  335. {
  336. //当前登录用户ID
  337. // String userid = ResourceUtil.getSessionUser().getId();
  338. // String warehouseid = "";
  339. // String hql1 = "from WarehouseEntity where responsiblePerson=? ";
  340. // List<WarehouseEntity> warehouseList = systemService.findHql(hql1, userid);
  341. // if(warehouseList.size() > 0)
  342. // {
  343. // warehouseid = warehouseList.get(0).getId();
  344. // }
  345. // orderDetailsEntityList = onhandReportDao.getDetails4NewBill(warehouseid);
  346. }else {
  347. String hql0 = "from MaterialsUsingDetailsEntity where 1 = 1 AND fK_ID =? ";
  348. try{
  349. orderDetailsEntityList = systemService.findHql(hql0,id0);
  350. }catch(Exception e){
  351. logger.info(e.getMessage());
  352. }
  353. }
  354. req.setAttribute("onhandReportDetailsList", orderDetailsEntityList);
  355. return new ModelAndView("cn/com/lzt/materialsusingdetails/materialsusingInitialDetailsList");
  356. }
  357. @RequestMapping(method = RequestMethod.GET)
  358. @ResponseBody
  359. public List<MaterialsUsingEntity> list() {
  360. List<MaterialsUsingEntity> listOrderss=mUsingService.getList(MaterialsUsingEntity.class);
  361. return listOrderss;
  362. }
  363. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  364. @ResponseBody
  365. public ResponseEntity<?> get(@PathVariable("id") String id) {
  366. MaterialsUsingEntity task = mUsingService.get(MaterialsUsingEntity.class, id);
  367. if (task == null) {
  368. return new ResponseEntity(HttpStatus.NOT_FOUND);
  369. }
  370. return new ResponseEntity(task, HttpStatus.OK);
  371. }
  372. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  373. @ResponseBody
  374. public ResponseEntity<?> create(@RequestBody MaterialsUsingPage materialsUsingPage, UriComponentsBuilder uriBuilder) {
  375. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  376. Set<ConstraintViolation<MaterialsUsingPage>> failures = validator.validate(materialsUsingPage);
  377. if (!failures.isEmpty()) {
  378. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  379. }
  380. //保存
  381. List<MaterialsUsingDetailsEntity> orderDetailsList = materialsUsingPage.getMaterialsUsingDetailsList();
  382. MaterialsUsingEntity materialsUsing = new MaterialsUsingEntity();
  383. try{
  384. MyBeanUtils.copyBeanNotNull2Bean(materialsUsing,materialsUsingPage);
  385. }catch(Exception e){
  386. logger.info(e.getMessage());
  387. }
  388. mUsingService.addMain(materialsUsing, orderDetailsList);
  389. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  390. String id = materialsUsingPage.getId();
  391. URI uri = uriBuilder.path("/api/onhandReportController/" + id).build().toUri();
  392. HttpHeaders headers = new HttpHeaders();
  393. headers.setLocation(uri);
  394. return new ResponseEntity(headers, HttpStatus.CREATED);
  395. }
  396. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  397. public ResponseEntity<?> update(@RequestBody MaterialsUsingPage materialsUsingPage) {
  398. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  399. Set<ConstraintViolation<MaterialsUsingPage>> failures = validator.validate(materialsUsingPage);
  400. if (!failures.isEmpty()) {
  401. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  402. }
  403. //保存
  404. List<MaterialsUsingDetailsEntity> orderDetailsList = materialsUsingPage.getMaterialsUsingDetailsList();
  405. MaterialsUsingEntity materialsUsing = new MaterialsUsingEntity();
  406. try{
  407. MyBeanUtils.copyBeanNotNull2Bean(materialsUsing,materialsUsingPage);
  408. }catch(Exception e){
  409. logger.info(e.getMessage());
  410. }
  411. mUsingService.updateMain(materialsUsing, orderDetailsList);
  412. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  413. return new ResponseEntity(HttpStatus.NO_CONTENT);
  414. }
  415. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  416. @ResponseStatus(HttpStatus.NO_CONTENT)
  417. public void delete(@PathVariable("id") String id) {
  418. MaterialsUsingEntity materialsUsing = mUsingService.get(MaterialsUsingEntity.class, id);
  419. mUsingService.delMain(materialsUsing);
  420. }
  421. /**
  422. * 解析SQL,返回字段集 支持多数据源
  423. * @param sql
  424. * @return
  425. */
  426. @SuppressWarnings({ "unchecked", "rawtypes" })
  427. @RequestMapping(params = "getProductInfo", method = RequestMethod.POST)
  428. @ResponseBody
  429. public Object getSqlFields(String goodsCode){
  430. TBGoodsInfoEntity goodInfo = null;
  431. TBPriceInfoEntity tBPriceInfoEntity = null;
  432. TBPriceInfoEntity tBPriceInfoEntityResult = null;
  433. Map reJson = new HashMap<String, Object>();
  434. try{
  435. //goodInfo = systemService.findUniqueByProperty(TBGoodsInfoEntity.class, "goodsCode",goodsCode);
  436. String hql_Goods = "from TBGoodsInfoEntity where 1 = 1 AND GOODS_CODE =? AND STATUS = 0 AND DELETE_FLAG = 0";
  437. List<TBGoodsInfoEntity> tBGoodsInfoEntityList = systemService.findHql(hql_Goods,goodsCode);
  438. if(tBGoodsInfoEntityList != null && tBGoodsInfoEntityList.size() > 0){
  439. goodInfo = tBGoodsInfoEntityList.get(0);
  440. }else{
  441. reJson.put("status", "false");
  442. return reJson;
  443. }
  444. //获取参数
  445. Object id0 = goodInfo.getId();
  446. String hql0 = "from TBPriceInfoEntity where 1 = 1 AND GOODS_ID =? ";
  447. List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql0,id0);
  448. List<String> unitlist = new ArrayList<String>();
  449. if(tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0){
  450. for(int i = 0 ;i < tBPriceInfoEntityList.size();i++){
  451. tBPriceInfoEntity = new TBPriceInfoEntity();
  452. tBPriceInfoEntity = tBPriceInfoEntityList.get(i);
  453. unitlist.add(tBPriceInfoEntity.getMeteringUnit());
  454. if(goodInfo.getPurchaseUnit() != null && tBPriceInfoEntity.getMeteringUnit() != null && goodInfo.getPurchaseUnit().equals(tBPriceInfoEntity.getMeteringUnit())){
  455. tBPriceInfoEntityResult = tBPriceInfoEntity;
  456. }
  457. }
  458. }
  459. if(tBPriceInfoEntityResult == null) {
  460. List<DictEntity> dictList = jeecgDictDao.querySystemDict("metering_calcu_unit");
  461. HashMap<String, String> map = new HashMap<>();
  462. for(DictEntity dic : dictList) {
  463. map.put(dic.getTypecode(), dic.getTypename());
  464. }
  465. StringBuffer sb = new StringBuffer();
  466. sb.append("可选择的计量单位:【");
  467. for(int i=0 ; i<unitlist.size() ; i++) {
  468. if(i>0) {
  469. sb.append("/");
  470. }
  471. sb.append(map.get(unitlist.get(i)));
  472. }
  473. sb.append("】");
  474. reJson.put("msg", sb.toString());
  475. }
  476. }catch (Exception e) {
  477. logger.info(e.getMessage());
  478. }
  479. reJson.put("status", "success");
  480. reJson.put("datainfo", goodInfo);
  481. reJson.put("pricinfo", tBPriceInfoEntityResult);
  482. return reJson;
  483. }
  484. /**
  485. * 解析SQL,返回字段集 支持多数据源
  486. * @param sql
  487. * @return
  488. */
  489. @SuppressWarnings({ "unchecked", "rawtypes" })
  490. @RequestMapping(params = "getPurchasePriceInfo", method = RequestMethod.POST)
  491. @ResponseBody
  492. public Object getSqlFields(String goodsCode,String purchaseUnit){
  493. Map reJson = new HashMap<String, Object>();
  494. TBGoodsInfoEntity goodInfo = null;
  495. if(StringUtils.isNotBlank(goodsCode) && StringUtils.isNotBlank(purchaseUnit)){
  496. TBPriceInfoEntity tBPriceInfoEntityResult = null;
  497. List<String> unitlist = new ArrayList<String>();
  498. try{
  499. goodInfo = systemService.findUniqueByProperty(TBGoodsInfoEntity.class, "goodsCode",goodsCode);
  500. String hql0 = "from TBPriceInfoEntity where 1 = 1 AND GOODS_ID = ?";
  501. List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql0,goodInfo.getId());
  502. if(tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0){
  503. for(TBPriceInfoEntity price : tBPriceInfoEntityList) {
  504. unitlist.add(price.getMeteringUnit());
  505. if(purchaseUnit.equals(price.getMeteringUnit())) {
  506. tBPriceInfoEntityResult = price;
  507. }
  508. }
  509. }
  510. if(tBPriceInfoEntityResult == null) {
  511. List<DictEntity> dictList = jeecgDictDao.querySystemDict("metering_calcu_unit");
  512. HashMap<String, String> map = new HashMap<>();
  513. for(DictEntity dic : dictList) {
  514. map.put(dic.getTypecode(), dic.getTypename());
  515. }
  516. StringBuffer sb = new StringBuffer();
  517. sb.append("可选择的计量单位:【");
  518. for(int i=0 ; i<unitlist.size() ; i++) {
  519. if(i>0) {
  520. sb.append("/");
  521. }
  522. sb.append(map.get(unitlist.get(i)));
  523. }
  524. sb.append("】");
  525. reJson.put("msg", sb.toString());
  526. }
  527. }catch (Exception e) {
  528. reJson.put("status", "fail");
  529. logger.info(e.getMessage());
  530. return reJson;
  531. }
  532. reJson.put("status", "success");
  533. reJson.put("pricinfo", tBPriceInfoEntityResult);
  534. }else{
  535. reJson.put("status", "success");
  536. reJson.put("pricinfo", null);
  537. }
  538. return reJson;
  539. }
  540. /**
  541. * 根据货品名称获取货品信息
  542. *
  543. * @param request
  544. * @param response
  545. * @param dataGrid
  546. * @throws ClassNotFoundException
  547. */
  548. @SuppressWarnings("rawtypes")
  549. @RequestMapping(params = "selRefDatagridGoods")
  550. public void selRefDatagridGoods(String classname, TBGoodsInfoEntity tBGoodsInfoEntity,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) throws Exception {
  551. Class cls = MyClassLoader.getClassByScn(classname);
  552. CriteriaQuery cq = new CriteriaQuery(cls, dataGrid);
  553. //查询条件组装器
  554. //自定义追加查询条件
  555. String[] unitstate = new String[]{Globals.Enable_Normal};
  556. cq.in("status", unitstate);
  557. cq.eq("deleteFlag", Globals.Delete_Normal.toString());
  558. // 检索用货品编码
  559. if(StringUtils.isNotBlank(tBGoodsInfoEntity.getGoodsCode())){
  560. //模糊查询
  561. cq.like("goodsCode", "%"+tBGoodsInfoEntity.getGoodsCode()+"%");
  562. }
  563. // 检索用货品名称
  564. if(StringUtils.isNotBlank(tBGoodsInfoEntity.getGoodsName())){
  565. //模糊查询
  566. cq.like("goodsName", "%"+tBGoodsInfoEntity.getGoodsName()+"%");
  567. }
  568. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, cls.newInstance());
  569. commonDao.getDataGridReturn(cq, true);
  570. List result = dataGrid.getResults();
  571. if(result != null && result.size() > 0){
  572. TBGoodsInfoEntity goodsInfoEntity = null;
  573. TBPriceInfoEntity tBPriceInfoEntity = null;
  574. for(int i = 0 ;i < result.size();i++){
  575. goodsInfoEntity = (TBGoodsInfoEntity)result.get(i);
  576. goodsInfoEntity.setGoodsDesc("");
  577. //获取参数
  578. Object id0 = goodsInfoEntity.getId();
  579. String hql0 = "from TBPriceInfoEntity where 1 = 1 AND GOODS_ID =? ";
  580. List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql0,id0);
  581. if(tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0){
  582. for(int j = 0 ;j < tBPriceInfoEntityList.size();j++){
  583. tBPriceInfoEntity = new TBPriceInfoEntity();
  584. tBPriceInfoEntity = tBPriceInfoEntityList.get(j);
  585. if(goodsInfoEntity.getPurchaseUnit() != null && tBPriceInfoEntity.getMeteringUnit() != null && goodsInfoEntity.getPurchaseUnit().equals(tBPriceInfoEntity.getMeteringUnit())){
  586. goodsInfoEntity.setGoodsDesc(tBPriceInfoEntity.getRetailPrice().toString());
  587. break;
  588. }
  589. }
  590. }
  591. }
  592. }
  593. try {
  594. //result =systemService.dealResultShowText4Entities(dataGrid.getResults(), cls);
  595. } catch (Exception e) {
  596. throw new BusinessException(e);
  597. }
  598. dataGrid.setResults(result);
  599. TagUtil.datagrid(response, dataGrid);
  600. }
  601. /**
  602. * 选择会员跳转页面
  603. *
  604. * @return
  605. */
  606. @RequestMapping(params = "selectReferGoods")
  607. public ModelAndView selectReferGoods(HttpServletRequest request) {
  608. ModelAndView mv = new ModelAndView("cn/com/lzt/purchase/selectGoodsInfo");
  609. String ids = oConvertUtils.getString(request.getParameter("ids"));
  610. mv.addObject("ids", ids);
  611. // 需要将前端的类路径传递到refer页面
  612. String clsname = oConvertUtils.getString(request.getParameter("classname"));
  613. mv.addObject("classname", clsname);
  614. mv.addObject("codefield", oConvertUtils.getString(request.getParameter("codefield")));
  615. mv.addObject("namefield", oConvertUtils.getString(request.getParameter("namefield")));
  616. mv.addObject("purchaseUnit", oConvertUtils.getString(request.getParameter("purchaseUnit")));
  617. mv.addObject("specification", oConvertUtils.getString(request.getParameter("specification")));
  618. mv.addObject("goodsDesc", oConvertUtils.getString(request.getParameter("goodsDesc")));
  619. mv.addObject("strEmpty", oConvertUtils.getString(request.getParameter("strEmpty")));
  620. return mv;
  621. }
  622. /**
  623. * 仓库弹出框
  624. * @param request
  625. * @param response
  626. * @param dataGrid
  627. * @throws ClassNotFoundException
  628. */
  629. @SuppressWarnings({"rawtypes" })
  630. @RequestMapping(params = "selRefDatagridWareHouse")
  631. public void selRefDatagridWareHouse(String classname,WarehouseEntity warehouse,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) throws Exception {
  632. Class cls = MyClassLoader.getClassByScn(classname);
  633. CriteriaQuery cq = new CriteriaQuery(cls, dataGrid);
  634. //自定义追加查询条件
  635. String[] unitstate = new String[]{Globals.Enable_Normal};
  636. cq.in("status", unitstate);
  637. cq.eq("deleteFlag", Globals.Delete_Normal.toString());
  638. String scope = oConvertUtils.getString(request.getParameter("scope"));
  639. if("part".equals(scope)) {
  640. HttpSession session = ContextHolderUtils.getSession();
  641. TSUser user = (TSUser)session.getAttribute("LOCAL_CLINET_USER");
  642. cq.eq("responsiblePerson", user.getId());
  643. }
  644. // 检索用仓库编码
  645. if(StringUtils.isNotBlank(warehouse.getWarehouseCode())){
  646. cq.eq("warehouseCode", warehouse.getWarehouseCode());
  647. }
  648. // 检索用仓库名称
  649. if(StringUtils.isNotBlank(warehouse.getWarehouseName())){
  650. cq.eq("warehouseName", warehouse.getWarehouseName());
  651. }
  652. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, cls.newInstance());
  653. commonDao.getDataGridReturn(cq, true);
  654. List result = dataGrid.getResults();
  655. try {
  656. //result =systemService.dealResultShowText4Entities(dataGrid.getResults(), cls);
  657. } catch (Exception e) {
  658. throw new BusinessException(e);
  659. }
  660. dataGrid.setResults(result);
  661. TagUtil.datagrid(response, dataGrid);
  662. }
  663. /**
  664. * 仓库弹出框
  665. * @return
  666. */
  667. @RequestMapping(params = "selectReferWareHouse")
  668. public ModelAndView selectReferWareHouse(HttpServletRequest request) {
  669. ModelAndView mv = new ModelAndView("cn/com/lzt/materialsusing/selectWareHouseInfo");
  670. String ids = oConvertUtils.getString(request.getParameter("ids"));
  671. mv.addObject("ids", ids);
  672. String scope = oConvertUtils.getString(request.getParameter("scope"));
  673. mv.addObject("scope",scope);
  674. // 需要将前端的类路径传递到refer页面
  675. String clsname = oConvertUtils.getString(request.getParameter("classname"));
  676. mv.addObject("classname", clsname);
  677. mv.addObject("codefield", oConvertUtils.getString(request.getParameter("codefield")));
  678. mv.addObject("namefield", oConvertUtils.getString(request.getParameter("namefield")));
  679. return mv;
  680. }
  681. /**
  682. * 取消物料领用单
  683. *
  684. * @author guoqing.yan
  685. */
  686. @RequestMapping(params = "doCancel")
  687. @ResponseBody
  688. public AjaxJson doCancel(String id, HttpServletRequest req) {
  689. AjaxJson j = new AjaxJson();
  690. String message = null;
  691. MaterialsUsingEntity materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, id);
  692. try{
  693. // 未审批和已经审批的可以取消
  694. if(materialsUsing.getOrderStatus() != null &&(materialsUsing.getOrderStatus().equals(Globals.UNAPPROVED) || materialsUsing.getOrderStatus().equals(Globals.APPROVED))){
  695. materialsUsing.setOrderStatus(Globals.CANCELED);//物料领用状态: 取消
  696. mUsingService.updateEntitie(materialsUsing);
  697. message = "单号:" + materialsUsing.getOrderOnumber() + "取消成功!";
  698. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  699. }else{
  700. message = "该单不能取消,请确认!";
  701. }
  702. }catch(Exception e){
  703. message = "操作失败!";
  704. }
  705. j.setMsg(message);
  706. return j;
  707. }
  708. /**
  709. * 取消物料领用单
  710. *
  711. * @author guoqing.yan
  712. */
  713. @RequestMapping(params = "doCancelAuditOrder")
  714. @ResponseBody
  715. public AjaxJson doCancelAuditOrder(String id,String refundvalue, HttpServletRequest req) {
  716. AjaxJson j = new AjaxJson();
  717. String message = null;
  718. MaterialsUsingEntity materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, id);
  719. // try{
  720. // // 首先判断该物料领用是否入库,如果入库则不能取消
  721. // Long godownOrderCount = systemService.getCountForJdbc("select count(1) from t_b_godown_entry where purchase_order_no='" + materialsUsing.getOrderOnumber() + "'");
  722. // // 未入库时候
  723. // if(godownOrderCount <=0){
  724. // if(StringUtils.isNotBlank(refundvalue)){
  725. // // 退的预付定金额
  726. // Double refundMoney = Double.parseDouble(refundvalue);
  727. // CollectMiddleEntity collectMiddleEntity = new CollectMiddleEntity();
  728. // collectMiddleEntity.setUnitId(materialsUsing.getSupplierId());// 供应商ID
  729. // collectMiddleEntity.setCollectionOrderOnumber(materialsUsing.getOrderOnumber());//物料领用号
  730. // collectMiddleEntity.setCollectionType(Globals.DEPOSIT_REFUND);// 预付定金退款
  731. // collectMiddleEntity.setAmountReceivable(refundMoney);
  732. // collectMiddleService.saveOrUpdate(collectMiddleEntity);
  733. // // 更新 往来单位表中的 应收余额
  734. // RelatedUnitsEntity relatedUnitsEntity = relatedUnitsService.get(RelatedUnitsEntity.class, materialsUsing.getSupplierId());
  735. // if(relatedUnitsEntity.getAmountReceivable() != null){
  736. // relatedUnitsEntity.setPrepaidBalance(refundMoney + relatedUnitsEntity.getAmountReceivable());// 预付余额
  737. // }else{
  738. // relatedUnitsEntity.setPrepaidBalance(refundMoney);// 预付余额
  739. // }
  740. // relatedUnitsService.updateEntitie(relatedUnitsEntity);
  741. // }
  742. // // 未审批和已经审批的可以取消
  743. // if(materialsUsing.getOrderStatus() != null && !materialsUsing.getOrderStatus().equals(Globals.CANCELED)){
  744. // materialsUsing.setOrderStatus(Globals.CANCELED);//物料领用状态: 取消
  745. // mUsingService.updateEntitie(orders);
  746. // message = "单号:" + materialsUsing.getOrderOnumber() + "取消成功!";
  747. // systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  748. // }else{
  749. // message = "该单已经取消,请确认!";
  750. // }
  751. // // 已经入库的时候
  752. // }else{
  753. // message = "该物料领用已经入库,不能取消,请确认!";
  754. // }
  755. //
  756. // }catch(Exception e){
  757. // message = "操作失败!";
  758. // }
  759. j.setMsg(message);
  760. return j;
  761. }
  762. /**
  763. * 审核通过
  764. *
  765. * @author guoqing.yan
  766. */
  767. @RequestMapping(params = "doAudit")
  768. @ResponseBody
  769. public AjaxJson doAudit(String id, HttpServletRequest req) {
  770. AjaxJson j = new AjaxJson();
  771. String message = null;
  772. MaterialsUsingEntity materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, id);
  773. try{
  774. // 未审批和已经审批的可以取消
  775. if(materialsUsing.getOrderStatus() != null &&materialsUsing.getOrderStatus().equals(Globals.UNAPPROVED)){
  776. // 物料领用单审核状态更新
  777. mUsingService.updateEntitie(materialsUsing);
  778. HttpSession session = ContextHolderUtils.getSession();
  779. TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER");
  780. materialsUsing.setAuditDate(new Date());
  781. materialsUsing.setOrderAuditor(tuser.getRealName());
  782. materialsUsing.setOrderStatus(Globals.APPROVED);//物料领用状态: 已审批
  783. message = "单号:" + materialsUsing.getOrderOnumber() + "已生效!";
  784. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  785. }else{
  786. message = "该单已经取消或者已生效,不能提交生效,请确认!";
  787. }
  788. }catch(Exception e){
  789. message = "操作失败!";
  790. }
  791. j.setMsg(message);
  792. return j;
  793. }
  794. }