| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839 |
- package cn.com.lzt.materialsusing.controller;
- import cn.com.lzt.arrangeduty.dao.UserOrgMinidao;
- import cn.com.lzt.goodsinfo.entity.TBGoodsInfoEntity;
- import cn.com.lzt.materialsusing.dao.MaterialsUsingDao;
- import cn.com.lzt.materialsusing.entity.MaterialsUsingEntity;
- import cn.com.lzt.materialsusing.page.MaterialsUsingPage;
- import cn.com.lzt.materialsusing.service.MaterialsUsingServiceI;
- import cn.com.lzt.materialsusingdetail.entity.MaterialsUsingDetailsEntity;
- import cn.com.lzt.priceinfo.entity.TBPriceInfoEntity;
- import cn.com.lzt.tools.OrderNumTools;
- import cn.com.lzt.warehouse.entity.WarehouseEntity;
- import org.apache.commons.lang.xwork.StringUtils;
- import org.apache.log4j.Logger;
- import org.jeecgframework.core.beanvalidator.BeanValidators;
- import org.jeecgframework.core.common.controller.BaseController;
- import org.jeecgframework.core.common.dao.ICommonDao;
- import org.jeecgframework.core.common.exception.BusinessException;
- import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
- import org.jeecgframework.core.common.model.json.AjaxJson;
- import org.jeecgframework.core.common.model.json.DataGrid;
- import org.jeecgframework.core.constant.Globals;
- import org.jeecgframework.core.util.*;
- import org.jeecgframework.tag.core.easyui.TagUtil;
- import org.jeecgframework.web.system.dao.JeecgDictDao;
- import org.jeecgframework.web.system.pojo.base.DictEntity;
- import org.jeecgframework.web.system.pojo.base.TSUser;
- import org.jeecgframework.web.system.service.SystemService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpHeaders;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.MediaType;
- import org.springframework.http.ResponseEntity;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.servlet.ModelAndView;
- import org.springframework.web.util.UriComponentsBuilder;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import javax.validation.ConstraintViolation;
- import javax.validation.Validator;
- import java.net.URI;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * @Title: Controller
- * @Description: 物料领用单
- * @author onlineGenerator
- * @date 2017-06-07 17:15:24
- * @version V1.0
- *
- */
- @Controller
- @RequestMapping("/materialsUsingController")
- public class MaterialsUsingController extends BaseController {
- /**
- * Logger for this class
- */
- private static final Logger logger = Logger.getLogger(MaterialsUsingController.class);
- @Autowired
- private MaterialsUsingServiceI mUsingService;
- @Autowired
- private SystemService systemService;
- @Autowired
- private Validator validator;
- @Autowired
- public ICommonDao commonDao = null;
- @Autowired
- private MaterialsUsingDao materialsUsingDao;
- @Autowired
- private JeecgDictDao jeecgDictDao;
- @Autowired
- private UserOrgMinidao userOrgdao;
- /**
- * 物料领用表列表 页面跳转
- *
- * @return
- */
- @RequestMapping(params = "list")
- public ModelAndView list(HttpServletRequest request) {
- ModelAndView mv = new ModelAndView("cn/com/lzt/materialsusing/materialsusingList");
- mv.addObject("userid", ResourceUtil.getSessionUser().getId());
- return mv;
- }
-
-
- @RequestMapping(params = "datagrid")
- public void datagrid(MaterialsUsingEntity materialsUsing,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- CriteriaQuery cq = new CriteriaQuery(MaterialsUsingEntity.class, dataGrid);
- String orderDateBegin = request.getParameter("orderDate_begin");
- String orderDateEnd = request.getParameter("orderDate_end");
- String orderOnumber = materialsUsing.getOrderOnumber();
- if(StringUtils.isNotBlank(orderOnumber)){
- materialsUsing.setOrderOnumber("*" +orderOnumber +"*");
- }
- //当前登录用户ID
- String userid = ResourceUtil.getSessionUser().getId();
- String hql1 = "from WarehouseEntity where responsiblePerson=? ";
- List<WarehouseEntity> warehouseList = systemService.findHql(hql1, userid);
- if(warehouseList.size() == 0)
- cq.eq("warehouseId","");
- else {
- List<String> wids = new ArrayList<String>();
- for(WarehouseEntity warehouse:warehouseList) {
- wids.add(warehouse.getId());
- }
- cq.in("warehouseId", wids.toArray());
- }
- //查询条件组装器
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, materialsUsing);
- try{
- //自定义追加查询条件
- if(StringUtils.isNotBlank(orderDateBegin) && StringUtils.isNotBlank(orderDateEnd)){
- cq.ge("orderDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateBegin + " 00:00:00"));
- cq.le("orderDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateEnd + " 23:59:59"));
- }
- }catch (Exception e) {
- throw new BusinessException(e.getMessage());
- }
- cq.notEq("orderStatus", "-1");
- cq.add();
- String warehouseId = materialsUsing.getWarehouseId();
- if(StringUtils.isNotBlank(warehouseId)) {
- cq.eq("warehouseId", warehouseId);
- cq.add();
- }
- List<MaterialsUsingEntity> list = mUsingService.getListByCriteriaQuery(cq, false);
- dataGrid.setResults(list);
- // this.mUsingService.getDataGridReturn(cq, false);
- TagUtil.datagrid(response, dataGrid);
- }
-
- /**
- * 删除物料领用表
- *
- * @return
- */
- @RequestMapping(params = "doDel")
- @ResponseBody
- public AjaxJson doDel(String id, HttpServletRequest request) {
- MaterialsUsingEntity materialsUsing ;
- AjaxJson j = new AjaxJson();
- materialsUsing = systemService.getEntity(MaterialsUsingEntity.class, id);
- String message = "物料领用表删除成功";
- try{
- mUsingService.delMain(materialsUsing);
- systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "物料领用表删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 批量删除物料领用表
- *
- * @return
- */
- @RequestMapping(params = "doBatchDel")
- @ResponseBody
- public AjaxJson doBatchDel(String ids,HttpServletRequest request){
- AjaxJson j = new AjaxJson();
- String message = "物料领用表删除成功";
- try{
- for(String id:ids.split(",")){
- MaterialsUsingEntity materialsUsing = systemService.getEntity(MaterialsUsingEntity.class,
- id
- );
- mUsingService.delMain(materialsUsing);
- systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
- }
- }catch(Exception e){
- e.printStackTrace();
- message = "物料领用表删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 添加物料领用表
- *
- * @param ids
- * @return
- */
- @RequestMapping(params = "doAdd")
- @ResponseBody
- public AjaxJson doAdd(MaterialsUsingEntity materialsUsing,MaterialsUsingPage materialsUsingPage, HttpServletRequest request) {
- List<MaterialsUsingDetailsEntity> orderDetailsList = materialsUsingPage.getMaterialsUsingDetailsList();
- AjaxJson j = new AjaxJson();
- String message = "添加成功";
- try{
- // 设置单号
- materialsUsing.setOrderOnumber(OrderNumTools.generateNextBillCode(getMaxLocalCode(),"MU"));
- materialsUsing.setOrderStatus(Globals.UNAPPROVED);// 未审批状态
- mUsingService.addMain(materialsUsing, orderDetailsList);
- systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "物料领用表添加失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
-
-
- private String getMaxLocalCode(){
- StringBuilder sb = new StringBuilder();
- sb.append("SELECT order_onumber FROM t_b_materialsusing");
- sb.append(" ORDER BY order_onumber DESC");
- List<Map<String, Object>> objMapList = systemService.findForJdbc(sb.toString(), 1, 1);
- String returnCode = null;
- if(objMapList!=null && objMapList.size()>0){
- returnCode = (String)objMapList.get(0).get("order_onumber");
- }
- return returnCode;
- }
- /**
- * 更新物料领用表
- *
- * @param ids
- * @return
- */
- @RequestMapping(params = "doUpdate")
- @ResponseBody
- public AjaxJson doUpdate(MaterialsUsingEntity materialsUsing,MaterialsUsingPage materialsUsingPage, HttpServletRequest request) {
- List<MaterialsUsingDetailsEntity> orderDetailsList = materialsUsingPage.getMaterialsUsingDetailsList();
- AjaxJson j = new AjaxJson();
- String message = "更新成功";
- try{
- mUsingService.updateMain(materialsUsing, orderDetailsList);
- systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "更新物料领用表失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 物料领用表新增页面跳转
- *
- * @return
- */
- @RequestMapping(params = "goAdd")
- public ModelAndView goAdd(MaterialsUsingEntity materialsUsing, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(materialsUsing.getId())) {
- materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, materialsUsing.getId());
- req.setAttribute("materialsUsingPage", materialsUsing);
- }else {
- //当前登录用户ID
- String userid = ResourceUtil.getSessionUser().getId();
- String hql1 = "from WarehouseEntity where responsiblePerson=? ";
- List<WarehouseEntity> warehouseList = systemService.findHql(hql1, userid);
- if(warehouseList.size() > 0)
- {
- materialsUsing.setWarehouseId(warehouseList.get(0).getId());
- materialsUsing.setWarehouseName( warehouseList.get(0).getWarehouseName());
- }
- req.setAttribute("materialsUsingPage", materialsUsing);
- }
- return new ModelAndView("cn/com/lzt/materialsusing/materialsusing-add");
- }
-
-
- /**
- * 物料领用表编辑页面跳转
- *
- * @return
- */
- @RequestMapping(params = "goUpdate")
- public ModelAndView goUpdate(MaterialsUsingEntity materialsUsing, HttpServletRequest req) {
- String isView = req.getParameter("viewFlag");
- req.setAttribute("viewFlag", isView);
- if (StringUtil.isNotEmpty(materialsUsing.getId())) {
- materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, materialsUsing.getId());
- // idandname(req, materialsUsing);
- req.setAttribute("materialsUsingPage", materialsUsing);
- }
- return new ModelAndView("cn/com/lzt/materialsusing/materialsusing-update");
- }
-
-
- /**
- * 加载明细列表[物料领用商品]
- *
- * @return
- */
- @RequestMapping(params = "MaterialsUsingDetailsList")
- public ModelAndView orderDetailsList(MaterialsUsingEntity materialsUsing, HttpServletRequest req) {
-
- List<MaterialsUsingDetailsEntity> materialsUsingDetailsEntityList = new ArrayList<MaterialsUsingDetailsEntity>();
- //===================================================================================
- //获取参数
- Object id0 = materialsUsing.getId();
- //===================================================================================
- //查询-物料领用商品
- if(id0 == null || id0.toString().length()!= 32){
- //当前登录用户ID
- String userid = ResourceUtil.getSessionUser().getId();
- String warehouseid = req.getParameter("warehouseid");
- if(warehouseid == null || warehouseid.trim().length() == 0) {
- String hql1 = "from WarehouseEntity where responsiblePerson=? ";
- List<WarehouseEntity> warehouseList = systemService.findHql(hql1, userid);
- if(warehouseList.size() > 0){
- warehouseid = warehouseList.get(0).getId();
- }
- }
- //查询此仓库上次填报的物料领用单
- materialsUsingDetailsEntityList = materialsUsingDao.getDetails4NewBill(warehouseid);
- for(int i = 0 ;i < materialsUsingDetailsEntityList.size();i++){
- MaterialsUsingDetailsEntity materialsUsingDetailsEntity = materialsUsingDetailsEntityList.get(i);
- TBGoodsInfoEntity goodsInfoEntity = systemService.get(TBGoodsInfoEntity.class, materialsUsingDetailsEntity.getGoodsId());
- materialsUsingDetailsEntity.setMeasureUnit(goodsInfoEntity.getSalesUnit());
- }
- }else {
- String hql0 = "from MaterialsUsingDetailsEntity where 1 = 1 AND fK_ID =? ";
- try{
- materialsUsingDetailsEntityList = systemService.findHql(hql0,id0);
- }catch(Exception e){
- logger.info(e.getMessage());
- }
-
- }
-
- req.setAttribute("materialsUsingDetailsList", materialsUsingDetailsEntityList);
- return new ModelAndView("cn/com/lzt/materialsusingdetails/materialsusingDetailsList");
- }
-
- /**
- * 加载明细列表[物料领用商品]
- *
- * @return
- */
- @RequestMapping(params = "OnhandReportInitialDetailsList")
- public ModelAndView OnhandReportInitialDetailsList(MaterialsUsingEntity materialsUsing, HttpServletRequest req) {
-
- List<MaterialsUsingDetailsEntity> orderDetailsEntityList = new ArrayList<MaterialsUsingDetailsEntity>();
- //===================================================================================
- //获取参数
- Object id0 = materialsUsing.getId();
- //===================================================================================
- //查询-物料领用商品
- if(id0 == null || id0.toString().length()!= 32)
- {
- //当前登录用户ID
- // String userid = ResourceUtil.getSessionUser().getId();
- // String warehouseid = "";
- // String hql1 = "from WarehouseEntity where responsiblePerson=? ";
- // List<WarehouseEntity> warehouseList = systemService.findHql(hql1, userid);
- // if(warehouseList.size() > 0)
- // {
- // warehouseid = warehouseList.get(0).getId();
- // }
- // orderDetailsEntityList = onhandReportDao.getDetails4NewBill(warehouseid);
-
- }else {
- String hql0 = "from MaterialsUsingDetailsEntity where 1 = 1 AND fK_ID =? ";
- try{
- orderDetailsEntityList = systemService.findHql(hql0,id0);
- }catch(Exception e){
- logger.info(e.getMessage());
- }
- }
- req.setAttribute("onhandReportDetailsList", orderDetailsEntityList);
- return new ModelAndView("cn/com/lzt/materialsusingdetails/materialsusingInitialDetailsList");
- }
-
- @RequestMapping(method = RequestMethod.GET)
- @ResponseBody
- public List<MaterialsUsingEntity> list() {
- List<MaterialsUsingEntity> listOrderss=mUsingService.getList(MaterialsUsingEntity.class);
- return listOrderss;
- }
-
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- @ResponseBody
- public ResponseEntity<?> get(@PathVariable("id") String id) {
- MaterialsUsingEntity task = mUsingService.get(MaterialsUsingEntity.class, id);
- if (task == null) {
- return new ResponseEntity(HttpStatus.NOT_FOUND);
- }
- return new ResponseEntity(task, HttpStatus.OK);
- }
-
- @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public ResponseEntity<?> create(@RequestBody MaterialsUsingPage materialsUsingPage, UriComponentsBuilder uriBuilder) {
- //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
- Set<ConstraintViolation<MaterialsUsingPage>> failures = validator.validate(materialsUsingPage);
- if (!failures.isEmpty()) {
- return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
- }
- //保存
- List<MaterialsUsingDetailsEntity> orderDetailsList = materialsUsingPage.getMaterialsUsingDetailsList();
-
- MaterialsUsingEntity materialsUsing = new MaterialsUsingEntity();
- try{
- MyBeanUtils.copyBeanNotNull2Bean(materialsUsing,materialsUsingPage);
- }catch(Exception e){
- logger.info(e.getMessage());
- }
- mUsingService.addMain(materialsUsing, orderDetailsList);
- //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
- String id = materialsUsingPage.getId();
- URI uri = uriBuilder.path("/api/onhandReportController/" + id).build().toUri();
- HttpHeaders headers = new HttpHeaders();
- headers.setLocation(uri);
- return new ResponseEntity(headers, HttpStatus.CREATED);
- }
-
- @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<?> update(@RequestBody MaterialsUsingPage materialsUsingPage) {
- //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
- Set<ConstraintViolation<MaterialsUsingPage>> failures = validator.validate(materialsUsingPage);
- if (!failures.isEmpty()) {
- return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
- }
- //保存
- List<MaterialsUsingDetailsEntity> orderDetailsList = materialsUsingPage.getMaterialsUsingDetailsList();
-
- MaterialsUsingEntity materialsUsing = new MaterialsUsingEntity();
- try{
- MyBeanUtils.copyBeanNotNull2Bean(materialsUsing,materialsUsingPage);
- }catch(Exception e){
- logger.info(e.getMessage());
- }
- mUsingService.updateMain(materialsUsing, orderDetailsList);
- //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
- return new ResponseEntity(HttpStatus.NO_CONTENT);
- }
- @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
- @ResponseStatus(HttpStatus.NO_CONTENT)
- public void delete(@PathVariable("id") String id) {
- MaterialsUsingEntity materialsUsing = mUsingService.get(MaterialsUsingEntity.class, id);
- mUsingService.delMain(materialsUsing);
- }
-
- /**
- * 解析SQL,返回字段集 支持多数据源
- * @param sql
- * @return
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @RequestMapping(params = "getProductInfo", method = RequestMethod.POST)
- @ResponseBody
- public Object getSqlFields(String goodsCode){
- TBGoodsInfoEntity goodInfo = null;
- TBPriceInfoEntity tBPriceInfoEntity = null;
- TBPriceInfoEntity tBPriceInfoEntityResult = null;
- Map reJson = new HashMap<String, Object>();
- try{
- //goodInfo = systemService.findUniqueByProperty(TBGoodsInfoEntity.class, "goodsCode",goodsCode);
- String hql_Goods = "from TBGoodsInfoEntity where 1 = 1 AND GOODS_CODE =? AND STATUS = 0 AND DELETE_FLAG = 0";
- List<TBGoodsInfoEntity> tBGoodsInfoEntityList = systemService.findHql(hql_Goods,goodsCode);
- if(tBGoodsInfoEntityList != null && tBGoodsInfoEntityList.size() > 0){
- goodInfo = tBGoodsInfoEntityList.get(0);
- }else{
- reJson.put("status", "false");
- return reJson;
- }
- //获取参数
- Object id0 = goodInfo.getId();
- String hql0 = "from TBPriceInfoEntity where 1 = 1 AND GOODS_ID =? ";
- List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql0,id0);
- List<String> unitlist = new ArrayList<String>();
- if(tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0){
- for(int i = 0 ;i < tBPriceInfoEntityList.size();i++){
- tBPriceInfoEntity = new TBPriceInfoEntity();
- tBPriceInfoEntity = tBPriceInfoEntityList.get(i);
- unitlist.add(tBPriceInfoEntity.getMeteringUnit());
- if(goodInfo.getPurchaseUnit() != null && tBPriceInfoEntity.getMeteringUnit() != null && goodInfo.getPurchaseUnit().equals(tBPriceInfoEntity.getMeteringUnit())){
- tBPriceInfoEntityResult = tBPriceInfoEntity;
- }
- }
- }
- if(tBPriceInfoEntityResult == null) {
- List<DictEntity> dictList = jeecgDictDao.querySystemDict("metering_calcu_unit");
- HashMap<String, String> map = new HashMap<>();
- for(DictEntity dic : dictList) {
- map.put(dic.getTypecode(), dic.getTypename());
- }
- StringBuffer sb = new StringBuffer();
- sb.append("可选择的计量单位:【");
- for(int i=0 ; i<unitlist.size() ; i++) {
- if(i>0) {
- sb.append("/");
- }
- sb.append(map.get(unitlist.get(i)));
- }
- sb.append("】");
- reJson.put("msg", sb.toString());
- }
- }catch (Exception e) {
- logger.info(e.getMessage());
- }
- reJson.put("status", "success");
- reJson.put("datainfo", goodInfo);
- reJson.put("pricinfo", tBPriceInfoEntityResult);
- return reJson;
- }
-
- /**
- * 解析SQL,返回字段集 支持多数据源
- * @param sql
- * @return
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @RequestMapping(params = "getPurchasePriceInfo", method = RequestMethod.POST)
- @ResponseBody
- public Object getSqlFields(String goodsCode,String purchaseUnit){
- Map reJson = new HashMap<String, Object>();
- TBGoodsInfoEntity goodInfo = null;
- if(StringUtils.isNotBlank(goodsCode) && StringUtils.isNotBlank(purchaseUnit)){
- TBPriceInfoEntity tBPriceInfoEntityResult = null;
- List<String> unitlist = new ArrayList<String>();
- try{
- goodInfo = systemService.findUniqueByProperty(TBGoodsInfoEntity.class, "goodsCode",goodsCode);
- String hql0 = "from TBPriceInfoEntity where 1 = 1 AND GOODS_ID = ?";
- List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql0,goodInfo.getId());
- if(tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0){
- for(TBPriceInfoEntity price : tBPriceInfoEntityList) {
- unitlist.add(price.getMeteringUnit());
- if(purchaseUnit.equals(price.getMeteringUnit())) {
- tBPriceInfoEntityResult = price;
- }
- }
- }
- if(tBPriceInfoEntityResult == null) {
- List<DictEntity> dictList = jeecgDictDao.querySystemDict("metering_calcu_unit");
- HashMap<String, String> map = new HashMap<>();
- for(DictEntity dic : dictList) {
- map.put(dic.getTypecode(), dic.getTypename());
- }
- StringBuffer sb = new StringBuffer();
- sb.append("可选择的计量单位:【");
- for(int i=0 ; i<unitlist.size() ; i++) {
- if(i>0) {
- sb.append("/");
- }
- sb.append(map.get(unitlist.get(i)));
- }
- sb.append("】");
- reJson.put("msg", sb.toString());
- }
- }catch (Exception e) {
- reJson.put("status", "fail");
- logger.info(e.getMessage());
- return reJson;
- }
- reJson.put("status", "success");
- reJson.put("pricinfo", tBPriceInfoEntityResult);
- }else{
- reJson.put("status", "success");
- reJson.put("pricinfo", null);
-
- }
- return reJson;
- }
-
- /**
- * 根据货品名称获取货品信息
- *
- * @param request
- * @param response
- * @param dataGrid
- * @throws ClassNotFoundException
- */
- @SuppressWarnings("rawtypes")
- @RequestMapping(params = "selRefDatagridGoods")
- public void selRefDatagridGoods(String classname, TBGoodsInfoEntity tBGoodsInfoEntity,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) throws Exception {
- Class cls = MyClassLoader.getClassByScn(classname);
- CriteriaQuery cq = new CriteriaQuery(cls, dataGrid);
- //查询条件组装器
- //自定义追加查询条件
- String[] unitstate = new String[]{Globals.Enable_Normal};
- cq.in("status", unitstate);
- cq.eq("deleteFlag", Globals.Delete_Normal.toString());
- // 检索用货品编码
- if(StringUtils.isNotBlank(tBGoodsInfoEntity.getGoodsCode())){
- //模糊查询
- cq.like("goodsCode", "%"+tBGoodsInfoEntity.getGoodsCode()+"%");
- }
- // 检索用货品名称
- if(StringUtils.isNotBlank(tBGoodsInfoEntity.getGoodsName())){
- //模糊查询
- cq.like("goodsName", "%"+tBGoodsInfoEntity.getGoodsName()+"%");
- }
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, cls.newInstance());
- commonDao.getDataGridReturn(cq, true);
- List result = dataGrid.getResults();
- if(result != null && result.size() > 0){
- TBGoodsInfoEntity goodsInfoEntity = null;
- TBPriceInfoEntity tBPriceInfoEntity = null;
- for(int i = 0 ;i < result.size();i++){
- goodsInfoEntity = (TBGoodsInfoEntity)result.get(i);
- goodsInfoEntity.setGoodsDesc("");
- //获取参数
- Object id0 = goodsInfoEntity.getId();
- String hql0 = "from TBPriceInfoEntity where 1 = 1 AND GOODS_ID =? ";
- List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql0,id0);
- if(tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0){
- for(int j = 0 ;j < tBPriceInfoEntityList.size();j++){
- tBPriceInfoEntity = new TBPriceInfoEntity();
- tBPriceInfoEntity = tBPriceInfoEntityList.get(j);
- if(goodsInfoEntity.getPurchaseUnit() != null && tBPriceInfoEntity.getMeteringUnit() != null && goodsInfoEntity.getPurchaseUnit().equals(tBPriceInfoEntity.getMeteringUnit())){
- goodsInfoEntity.setGoodsDesc(tBPriceInfoEntity.getRetailPrice().toString());
- break;
- }
- }
- }
- }
- }
- try {
- //result =systemService.dealResultShowText4Entities(dataGrid.getResults(), cls);
- } catch (Exception e) {
- throw new BusinessException(e);
- }
- dataGrid.setResults(result);
- TagUtil.datagrid(response, dataGrid);
- }
- /**
- * 选择会员跳转页面
- *
- * @return
- */
- @RequestMapping(params = "selectReferGoods")
- public ModelAndView selectReferGoods(HttpServletRequest request) {
- ModelAndView mv = new ModelAndView("cn/com/lzt/purchase/selectGoodsInfo");
- String ids = oConvertUtils.getString(request.getParameter("ids"));
- mv.addObject("ids", ids);
- // 需要将前端的类路径传递到refer页面
- String clsname = oConvertUtils.getString(request.getParameter("classname"));
- mv.addObject("classname", clsname);
- mv.addObject("codefield", oConvertUtils.getString(request.getParameter("codefield")));
- mv.addObject("namefield", oConvertUtils.getString(request.getParameter("namefield")));
- mv.addObject("purchaseUnit", oConvertUtils.getString(request.getParameter("purchaseUnit")));
- mv.addObject("specification", oConvertUtils.getString(request.getParameter("specification")));
- mv.addObject("goodsDesc", oConvertUtils.getString(request.getParameter("goodsDesc")));
- mv.addObject("strEmpty", oConvertUtils.getString(request.getParameter("strEmpty")));
- return mv;
- }
-
- /**
- * 仓库弹出框
- * @param request
- * @param response
- * @param dataGrid
- * @throws ClassNotFoundException
- */
- @SuppressWarnings({"rawtypes" })
- @RequestMapping(params = "selRefDatagridWareHouse")
- public void selRefDatagridWareHouse(String classname,WarehouseEntity warehouse,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) throws Exception {
- Class cls = MyClassLoader.getClassByScn(classname);
- CriteriaQuery cq = new CriteriaQuery(cls, dataGrid);
- //自定义追加查询条件
- String[] unitstate = new String[]{Globals.Enable_Normal};
- cq.in("status", unitstate);
- cq.eq("deleteFlag", Globals.Delete_Normal.toString());
- String scope = oConvertUtils.getString(request.getParameter("scope"));
- if("part".equals(scope)) {
- HttpSession session = ContextHolderUtils.getSession();
- TSUser user = (TSUser)session.getAttribute("LOCAL_CLINET_USER");
- cq.eq("responsiblePerson", user.getId());
- }
- // 检索用仓库编码
- if(StringUtils.isNotBlank(warehouse.getWarehouseCode())){
- cq.eq("warehouseCode", warehouse.getWarehouseCode());
- }
- // 检索用仓库名称
- if(StringUtils.isNotBlank(warehouse.getWarehouseName())){
- cq.eq("warehouseName", warehouse.getWarehouseName());
- }
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, cls.newInstance());
- commonDao.getDataGridReturn(cq, true);
- List result = dataGrid.getResults();
- try {
- //result =systemService.dealResultShowText4Entities(dataGrid.getResults(), cls);
- } catch (Exception e) {
- throw new BusinessException(e);
- }
- dataGrid.setResults(result);
- TagUtil.datagrid(response, dataGrid);
- }
- /**
- * 仓库弹出框
- * @return
- */
- @RequestMapping(params = "selectReferWareHouse")
- public ModelAndView selectReferWareHouse(HttpServletRequest request) {
- ModelAndView mv = new ModelAndView("cn/com/lzt/materialsusing/selectWareHouseInfo");
- String ids = oConvertUtils.getString(request.getParameter("ids"));
- mv.addObject("ids", ids);
-
- String scope = oConvertUtils.getString(request.getParameter("scope"));
- mv.addObject("scope",scope);
- // 需要将前端的类路径传递到refer页面
- String clsname = oConvertUtils.getString(request.getParameter("classname"));
- mv.addObject("classname", clsname);
- mv.addObject("codefield", oConvertUtils.getString(request.getParameter("codefield")));
- mv.addObject("namefield", oConvertUtils.getString(request.getParameter("namefield")));
- return mv;
- }
- /**
- * 取消物料领用单
- *
- * @author guoqing.yan
- */
- @RequestMapping(params = "doCancel")
- @ResponseBody
- public AjaxJson doCancel(String id, HttpServletRequest req) {
- AjaxJson j = new AjaxJson();
- String message = null;
- MaterialsUsingEntity materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, id);
- try{
- // 未审批和已经审批的可以取消
- if(materialsUsing.getOrderStatus() != null &&(materialsUsing.getOrderStatus().equals(Globals.UNAPPROVED) || materialsUsing.getOrderStatus().equals(Globals.APPROVED))){
- materialsUsing.setOrderStatus(Globals.CANCELED);//物料领用状态: 取消
- mUsingService.updateEntitie(materialsUsing);
- message = "单号:" + materialsUsing.getOrderOnumber() + "取消成功!";
- systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
- }else{
- message = "该单不能取消,请确认!";
- }
- }catch(Exception e){
- message = "操作失败!";
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 取消物料领用单
- *
- * @author guoqing.yan
- */
- @RequestMapping(params = "doCancelAuditOrder")
- @ResponseBody
- public AjaxJson doCancelAuditOrder(String id,String refundvalue, HttpServletRequest req) {
- AjaxJson j = new AjaxJson();
- String message = null;
- MaterialsUsingEntity materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, id);
- // try{
- // // 首先判断该物料领用是否入库,如果入库则不能取消
- // Long godownOrderCount = systemService.getCountForJdbc("select count(1) from t_b_godown_entry where purchase_order_no='" + materialsUsing.getOrderOnumber() + "'");
- // // 未入库时候
- // if(godownOrderCount <=0){
- // if(StringUtils.isNotBlank(refundvalue)){
- // // 退的预付定金额
- // Double refundMoney = Double.parseDouble(refundvalue);
- // CollectMiddleEntity collectMiddleEntity = new CollectMiddleEntity();
- // collectMiddleEntity.setUnitId(materialsUsing.getSupplierId());// 供应商ID
- // collectMiddleEntity.setCollectionOrderOnumber(materialsUsing.getOrderOnumber());//物料领用号
- // collectMiddleEntity.setCollectionType(Globals.DEPOSIT_REFUND);// 预付定金退款
- // collectMiddleEntity.setAmountReceivable(refundMoney);
- // collectMiddleService.saveOrUpdate(collectMiddleEntity);
- // // 更新 往来单位表中的 应收余额
- // RelatedUnitsEntity relatedUnitsEntity = relatedUnitsService.get(RelatedUnitsEntity.class, materialsUsing.getSupplierId());
- // if(relatedUnitsEntity.getAmountReceivable() != null){
- // relatedUnitsEntity.setPrepaidBalance(refundMoney + relatedUnitsEntity.getAmountReceivable());// 预付余额
- // }else{
- // relatedUnitsEntity.setPrepaidBalance(refundMoney);// 预付余额
- // }
- // relatedUnitsService.updateEntitie(relatedUnitsEntity);
- // }
- // // 未审批和已经审批的可以取消
- // if(materialsUsing.getOrderStatus() != null && !materialsUsing.getOrderStatus().equals(Globals.CANCELED)){
- // materialsUsing.setOrderStatus(Globals.CANCELED);//物料领用状态: 取消
- // mUsingService.updateEntitie(orders);
- // message = "单号:" + materialsUsing.getOrderOnumber() + "取消成功!";
- // systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
- // }else{
- // message = "该单已经取消,请确认!";
- // }
- // // 已经入库的时候
- // }else{
- // message = "该物料领用已经入库,不能取消,请确认!";
- // }
- //
- // }catch(Exception e){
- // message = "操作失败!";
- // }
- j.setMsg(message);
- return j;
- }
-
- /**
- * 审核通过
- *
- * @author guoqing.yan
- */
- @RequestMapping(params = "doAudit")
- @ResponseBody
- public AjaxJson doAudit(String id, HttpServletRequest req) {
- AjaxJson j = new AjaxJson();
- String message = null;
- MaterialsUsingEntity materialsUsing = mUsingService.getEntity(MaterialsUsingEntity.class, id);
- try{
- // 未审批和已经审批的可以取消
- if(materialsUsing.getOrderStatus() != null &&materialsUsing.getOrderStatus().equals(Globals.UNAPPROVED)){
- // 物料领用单审核状态更新
- mUsingService.updateEntitie(materialsUsing);
- HttpSession session = ContextHolderUtils.getSession();
- TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER");
- materialsUsing.setAuditDate(new Date());
- materialsUsing.setOrderAuditor(tuser.getRealName());
- materialsUsing.setOrderStatus(Globals.APPROVED);//物料领用状态: 已审批
- message = "单号:" + materialsUsing.getOrderOnumber() + "已生效!";
- systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
- }else{
- message = "该单已经取消或者已生效,不能提交生效,请确认!";
- }
- }catch(Exception e){
- message = "操作失败!";
- }
- j.setMsg(message);
- return j;
- }
- }
|