| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710 |
- package cn.com.lzt.goodsinfo.controller;
- import java.io.IOException;
- import java.net.URI;
- import java.util.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import javax.validation.ConstraintViolation;
- import javax.validation.Validator;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.log4j.Logger;
- import org.jeecgframework.core.beanvalidator.BeanValidators;
- import org.jeecgframework.core.common.controller.BaseController;
- 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.minidao.pojo.MiniDaoPage;
- import org.jeecgframework.poi.excel.ExcelImportUtil;
- import org.jeecgframework.poi.excel.entity.ExportParams;
- import org.jeecgframework.poi.excel.entity.ImportParams;
- import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
- import org.jeecgframework.tag.core.easyui.TagUtil;
- 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.ui.ModelMap;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.bind.annotation.ResponseStatus;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.multipart.MultipartHttpServletRequest;
- import org.springframework.web.servlet.ModelAndView;
- import org.springframework.web.util.UriComponentsBuilder;
- import cn.com.lzt.goodscategory.entity.TBGoodsCategoryEntity;
- import cn.com.lzt.goodsinfo.dao.TBGoodsDao;
- import cn.com.lzt.goodsinfo.entity.TBGoodsInfoEntity;
- import cn.com.lzt.goodsinfo.entity.TBGoodsRelatedUnitPriceEntity;
- import cn.com.lzt.goodsinfo.page.TBGoodsInfoPage;
- import cn.com.lzt.goodsinfo.service.TBGoodsInfoServiceI;
- import cn.com.lzt.priceinfo.entity.TBPriceInfoEntity;
- import cn.com.lzt.relatedunits.entity.RelatedUnitsEntity;
- import cn.com.lzt.stockinfo.entity.TBStockInfoEntity;
- import cn.com.lzt.tools.SaltUtil;
- /**
- * @author onlineGenerator
- * @version V1.0
- * @Title: Controller
- * @Description: 货品信息
- * @date 2017-06-08 20:42:39
- */
- @Controller
- @RequestMapping("/tBGoodsInfoController")
- public class TBGoodsInfoController extends BaseController {
- /**
- * Logger for this class
- */
- private static final Logger logger = Logger.getLogger(TBGoodsInfoController.class);
- @Autowired
- private TBGoodsInfoServiceI tBGoodsInfoService;
- @Autowired
- private SystemService systemService;
- @Autowired
- private Validator validator;
- @Autowired
- private TBGoodsDao goodsDao;
- /**
- * 货品信息列表 页面跳转
- *
- * @return
- */
- @RequestMapping(params = "list")
- public ModelAndView list(HttpServletRequest request) {
- return new ModelAndView("cn/com/lzt/goodsinfo/tBGoodsInfoList");
- }
- /**
- * easyui AJAX请求数据
- *
- * @param request
- * @param response
- * @param dataGrid
- */
- @RequestMapping(params = "datagrid")
- public void datagrid(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- String sqlString = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
- if(StringUtils.isNotEmpty(sqlString)){
- String[] sqlSplit =sqlString.split("'");
- String belongCategorySql = sqlSplit[1];
- tBGoodsInfo.setBelongCategory(belongCategorySql);
- if(sqlString.contains("!=")){
- sqlString = belongCategorySql;
- tBGoodsInfo.setBelongCategory(null);
- }else{
- sqlString = null;
- }
- }
- MiniDaoPage<TBGoodsInfoEntity> page = null;
- page = goodsDao.getGoodsInfoList(tBGoodsInfo, dataGrid.getPage(), dataGrid.getRows(), sqlString);
- dataGrid.setResults(page.getResults());
- dataGrid.setTotal(page.getTotal());
- TagUtil.datagrid(response, dataGrid);
- }
- /**
- * 删除货品信息
- *
- * @return
- */
- @RequestMapping(params = "doDel")
- @ResponseBody
- public AjaxJson doDel(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest request) {
- AjaxJson j = new AjaxJson();
- tBGoodsInfo = systemService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
- String message = "货品信息 删除成功";
- try {
- tBGoodsInfoService.delMain(tBGoodsInfo);
- 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 = "logicDel")
- @ResponseBody
- public AjaxJson logicDel(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- tBGoodsInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
- message = "货品信息 删除成功";
- try {
- tBGoodsInfo.setDeleteFlag(Globals.Delete_Forbidden.toString());
- tBGoodsInfoService.logicDelMain(tBGoodsInfo);
- 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(",")) {
- TBGoodsInfoEntity tBGoodsInfo = systemService.getEntity(TBGoodsInfoEntity.class,
- id
- );
- tBGoodsInfo.setDeleteFlag("1");
- tBGoodsInfoService.updateEntitie(tBGoodsInfo);
- 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 = "doAdd")
- @ResponseBody
- public AjaxJson doAdd(TBGoodsInfoEntity tBGoodsInfo) {
- AjaxJson j = new AjaxJson();
- String message;
- // TODO (测试阶段:刘梦祥-2021年11月24日23:00:23)
- try {
- // 首先判断是否是新增操作(即存在id为编辑操作)
- HttpSession session = ContextHolderUtils.getSession();
- TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER");
- // 添加默认属性(即使数据库有默认字段填充也不行)
- tBGoodsInfo.setStatus("0");
- tBGoodsInfo.setDeleteFlag("0");
- if (tBGoodsInfo.getId() != null && !"".equals(tBGoodsInfo.getId())) {
- // 编辑操作
- tBGoodsInfo.setUpdateName(tuser.getRealName());
- tBGoodsInfo.setUpdateDate(new Date());
- tBGoodsInfo.setUpdateBy(tuser.getUserName());
- this.tBGoodsInfoService.updateEntitie(tBGoodsInfo);
- message = "编辑成功";
- } else {
- // 新增操作
- tBGoodsInfo.setId(UUID.randomUUID().toString());
- tBGoodsInfo.setCreateName(tuser.getRealName());
- tBGoodsInfo.setCreateDate(new Date());
- tBGoodsInfo.setCreateBy(tuser.getUserName());
- this.tBGoodsInfoService.save(tBGoodsInfo);
- message = "添加成功";
- }
- systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
- } catch (Exception e) {
- j.setSuccess(false);
- e.printStackTrace();
- message = "货品信息添加或修改失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 更新货品信息
- *
- * @return
- */
- @RequestMapping(params = "doUpdate")
- @ResponseBody
- public AjaxJson doUpdate(TBGoodsInfoEntity tBGoodsInfo, TBGoodsInfoPage tBGoodsInfoPage, HttpServletRequest request) {
- List<TBStockInfoEntity> tBStockInfoList = tBGoodsInfoPage.getTBStockInfoList();
- List<TBPriceInfoEntity> tBPriceInfoList = tBGoodsInfoPage.getTBPriceInfoList();
- List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoList = tBGoodsInfoPage.getTBRelatedUnitPriceInfoList();
- AjaxJson j = new AjaxJson();
- String message = "更新成功";
- try {
- if (tBGoodsInfo.getBelongCategory() == null || "".equals(tBGoodsInfo.getBelongCategory())) {
- message = "请选择所属分类!";
- j.setMsg(message);
- j.setSuccess(false);
- return j;
- }
- if (tBPriceInfoList == null || tBPriceInfoList.size() <= 0) {
- message = "请确认价格信息是否修改后,再提交页面。";
- j.setMsg(message);
- j.setSuccess(false);
- return j;
- }
- int baseUnitCount = 0;
- Map<String, TBPriceInfoEntity> map = new HashMap<String, TBPriceInfoEntity>();
- for (int i = 0; i < tBPriceInfoList.size(); i++) {
- TBPriceInfoEntity priceInfo = tBPriceInfoList.get(i);
- if (priceInfo.getMeteringUnit() != null && !"".equals(priceInfo.getMeteringUnit())) {
- map.put(priceInfo.getMeteringUnit(), priceInfo);
- //必须填入一条基本单位的价格信息
- if (priceInfo.getMeteringUnit().equals(tBGoodsInfo.getBaseUnit())) {
- baseUnitCount++;
- }
- }
- }
- if (tBPriceInfoList.size() != map.size()) {
- message = "计量单位不能重复,请重新选择!";
- j.setMsg(message);
- j.setSuccess(false);
- return j;
- }
- if (!map.containsKey(tBGoodsInfo.getSalesUnit())) {
- message = "申购时默认计量单位未在价格信息里定义,请重新选择!";
- j.setMsg(message);
- j.setSuccess(false);
- return j;
- }
- if (!map.containsKey(tBGoodsInfo.getPurchaseUnit())) {
- message = "采购时默认计量单位未在价格信息里定义,请重新选择!";
- j.setMsg(message);
- j.setSuccess(false);
- return j;
- }
- if (baseUnitCount == 0) {
- message = "必须填入一条基本单位的价格信息!";
- j.setMsg(message);
- j.setSuccess(false);
- return j;
- }
- if (baseUnitCount > 1) {
- message = "只能填入一条基本单位的价格信息!";
- j.setMsg(message);
- j.setSuccess(false);
- return j;
- }
- Map<String, TBGoodsRelatedUnitPriceEntity> rumap = new HashMap<String, TBGoodsRelatedUnitPriceEntity>();
- boolean relatedUnitRepetitionflag = false;
- for (int i = 0; i < tBRelatedUnitPriceInfoList.size(); i++) {
- TBGoodsRelatedUnitPriceEntity priceInfo = tBRelatedUnitPriceInfoList.get(i);
- if (priceInfo.getMeteringUnit() != null && !"".equals(priceInfo.getMeteringUnit())) {
- rumap.put(priceInfo.getRelatedunitid(), priceInfo);
- } else {
- relatedUnitRepetitionflag = true;
- break;
- }
- }
- if (relatedUnitRepetitionflag) {
- message = "供应商价格不能重复,请修改后再保存";
- j.setMsg(message);
- j.setSuccess(false);
- return j;
- }
- if (tBGoodsInfo.getBelongCategory() != null) {
- TBGoodsCategoryEntity category = systemService.get(TBGoodsCategoryEntity.class, tBGoodsInfo.getBelongCategory());
- if (category != null) {
- tBGoodsInfo.setBelongCategoryCode(category.getCategoryCode());
- }
- }
- tBGoodsInfo.setStatus(Globals.Enabled.toString());
- tBGoodsInfo.setDeleteFlag(Globals.Delete_Normal.toString());
- tBGoodsInfoService.updateMain(tBGoodsInfo, tBStockInfoList, tBPriceInfoList, tBRelatedUnitPriceInfoList);
- 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(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(tBGoodsInfo.getId())) {
- tBGoodsInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
- req.setAttribute("tBGoodsInfoPage", tBGoodsInfo);
- }
- return new ModelAndView("cn/com/lzt/goodsinfo/tBGoodsInfo-AUD");
- }
- /**
- * 未知型号商品添加
- */
- @RequestMapping(params = "goUnknownAdd")
- public ModelAndView goUnknownAdd(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(tBGoodsInfo.getId())) {
- tBGoodsInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
- req.setAttribute("tBGoodsInfoPage", tBGoodsInfo);
- }
- return new ModelAndView("cn/com/lzt/goodsinfo/tBGoodsInfo-unknown-add");
- }
- /**
- * 货品信息编辑页面跳转
- *
- * @return
- */
- @RequestMapping(params = "goUpdate")
- public ModelAndView goUpdate(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(tBGoodsInfo.getId())) {
- tBGoodsInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
- req.setAttribute("entity", tBGoodsInfo);
- }
- return new ModelAndView("cn/com/lzt/goodsinfo/tBGoodsInfo-AUD");
- }
- /**
- * 加载明细列表[库存信息]
- *
- * @return
- */
- @RequestMapping(params = "tBStockInfoList")
- public ModelAndView tBStockInfoList(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
- //===================================================================================
- //获取参数
- Object id0 = tBGoodsInfo.getId();
- //===================================================================================
- //查询-库存信息
- String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? ";
- try {
- List<TBStockInfoEntity> tBStockInfoEntityList = systemService.findHql(hql0, id0);
- req.setAttribute("tBStockInfoList", tBStockInfoEntityList);
- } catch (Exception e) {
- logger.info(e.getMessage());
- }
- return new ModelAndView("cn/com/lzt/stockinfo/tBStockInfoList");
- }
- /**
- * 加载明细列表[价格信息]
- *
- * @return
- */
- @RequestMapping(params = "tBPriceInfoList")
- public ModelAndView tBPriceInfoList(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
- //===================================================================================
- //获取参数
- Object id1 = tBGoodsInfo.getId();
- //===================================================================================
- //查询-价格信息
- String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? ";
- try {
- List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql1, id1);
- req.setAttribute("tBPriceInfoList", tBPriceInfoEntityList);
- } catch (Exception e) {
- logger.info(e.getMessage());
- }
- return new ModelAndView("cn/com/lzt/priceinfo/tBPriceInfoList");
- }
- @RequestMapping(params = "tBRelatedUnitPriceInfoList")
- public ModelAndView tBRelatedUnitPriceInfoList(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
- //===================================================================================
- //获取参数
- Object id1 = tBGoodsInfo.getId();
- //===================================================================================
- //查询-价格信息
- String hql1 = "from TBGoodsRelatedUnitPriceEntity where 1 = 1 AND gOODS_ID =? ";
- try {
- List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoEntityList = systemService.findHql(hql1, id1);
- req.setAttribute("tBRelatedUnitPriceInfoList", tBRelatedUnitPriceInfoEntityList);
- } catch (Exception e) {
- logger.info(e.getMessage());
- }
- return new ModelAndView("cn/com/lzt/goodsinfo/tBRelatedUnitPriceInfoList");
- }
- /**
- * 导出excel
- *
- * @param request
- * @param response
- */
- @RequestMapping(params = "exportXls")
- public String exportXls(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, ModelMap map) {
- CriteriaQuery cq = new CriteriaQuery(TBGoodsInfoEntity.class, dataGrid);
- //查询条件组装器
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tBGoodsInfo);
- try {
- //自定义追加查询条件
- } catch (Exception e) {
- throw new BusinessException(e.getMessage());
- }
- cq.add();
- List<TBGoodsInfoEntity> list = this.tBGoodsInfoService.getListByCriteriaQuery(cq, false);
- List<TBGoodsInfoPage> pageList = new ArrayList<TBGoodsInfoPage>();
- if (list != null && list.size() > 0) {
- for (TBGoodsInfoEntity entity : list) {
- try {
- TBGoodsInfoPage page = new TBGoodsInfoPage();
- MyBeanUtils.copyBeanNotNull2Bean(entity, page);
- Object id0 = entity.getId();
- String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? ";
- List<TBStockInfoEntity> tBStockInfoEntityList = systemService.findHql(hql0, id0);
- page.setTBStockInfoList(tBStockInfoEntityList);
- Object id1 = entity.getId();
- String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? ";
- List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql1, id1);
- page.setTBPriceInfoList(tBPriceInfoEntityList);
- pageList.add(page);
- } catch (Exception e) {
- logger.info(e.getMessage());
- }
- }
- }
- map.put(NormalExcelConstants.FILE_NAME, "货品信息");
- map.put(NormalExcelConstants.CLASS, TBGoodsInfoPage.class);
- map.put(NormalExcelConstants.PARAMS, new ExportParams("货品信息列表", "导出人:Jeecg",
- "导出信息"));
- map.put(NormalExcelConstants.DATA_LIST, pageList);
- return NormalExcelConstants.JEECG_EXCEL_VIEW;
- }
- /**
- * 通过excel导入数据
- *
- * @param request
- * @param
- * @return
- */
- @RequestMapping(params = "importExcel", method = RequestMethod.POST)
- @ResponseBody
- public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
- AjaxJson j = new AjaxJson();
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
- for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
- MultipartFile file = entity.getValue();// 获取上传文件对象
- ImportParams params = new ImportParams();
- params.setTitleRows(2);
- params.setHeadRows(2);
- params.setNeedSave(true);
- try {
- List<TBGoodsInfoPage> list = ExcelImportUtil.importExcel(file.getInputStream(), TBGoodsInfoPage.class, params);
- TBGoodsInfoEntity entity1 = null;
- for (TBGoodsInfoPage page : list) {
- entity1 = new TBGoodsInfoEntity();
- MyBeanUtils.copyBeanNotNull2Bean(page, entity1);
- tBGoodsInfoService.addMain(entity1, page.getTBStockInfoList(), page.getTBPriceInfoList(), page.getTBRelatedUnitPriceInfoList());
- }
- j.setMsg("文件导入成功!");
- } catch (Exception e) {
- j.setMsg("文件导入失败!");
- logger.error(ExceptionUtil.getExceptionMessage(e));
- } finally {
- try {
- file.getInputStream().close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return j;
- }
- /**
- * 导出excel 使模板
- */
- @RequestMapping(params = "exportXlsByT")
- public String exportXlsByT(ModelMap map) {
- map.put(NormalExcelConstants.FILE_NAME, "货品信息");
- map.put(NormalExcelConstants.CLASS, TBGoodsInfoPage.class);
- map.put(NormalExcelConstants.PARAMS, new ExportParams("货品信息列表", "导出人:" + ResourceUtil.getSessionUserName().getRealName(),
- "导出信息"));
- map.put(NormalExcelConstants.DATA_LIST, new ArrayList());
- return NormalExcelConstants.JEECG_EXCEL_VIEW;
- }
- /**
- * 导入功能跳转
- *
- * @return
- */
- @RequestMapping(params = "upload")
- public ModelAndView upload(HttpServletRequest req) {
- req.setAttribute("controller_name", "tBGoodsInfoController");
- return new ModelAndView("common/upload/pub_excel_upload");
- }
- @RequestMapping(method = RequestMethod.GET)
- @ResponseBody
- public List<TBGoodsInfoEntity> list() {
- List<TBGoodsInfoEntity> listTBGoodsInfos = tBGoodsInfoService.getList(TBGoodsInfoEntity.class);
- return listTBGoodsInfos;
- }
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- @ResponseBody
- public ResponseEntity<?> get(@PathVariable("id") String id) {
- TBGoodsInfoEntity task = tBGoodsInfoService.get(TBGoodsInfoEntity.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 TBGoodsInfoPage tBGoodsInfoPage, UriComponentsBuilder uriBuilder) {
- //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
- Set<ConstraintViolation<TBGoodsInfoPage>> failures = validator.validate(tBGoodsInfoPage);
- if (!failures.isEmpty()) {
- return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
- }
- //保存
- List<TBStockInfoEntity> tBStockInfoList = tBGoodsInfoPage.getTBStockInfoList();
- List<TBPriceInfoEntity> tBPriceInfoList = tBGoodsInfoPage.getTBPriceInfoList();
- TBGoodsInfoEntity tBGoodsInfo = new TBGoodsInfoEntity();
- try {
- MyBeanUtils.copyBeanNotNull2Bean(tBGoodsInfo, tBGoodsInfoPage);
- } catch (Exception e) {
- logger.info(e.getMessage());
- }
- tBGoodsInfoService.addMain(tBGoodsInfo, tBStockInfoList, tBPriceInfoList, tBGoodsInfoPage.getTBRelatedUnitPriceInfoList());
- //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
- String id = tBGoodsInfoPage.getId();
- URI uri = uriBuilder.path("/rest/tBGoodsInfoController/" + 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 TBGoodsInfoPage tBGoodsInfoPage) {
- //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
- Set<ConstraintViolation<TBGoodsInfoPage>> failures = validator.validate(tBGoodsInfoPage);
- if (!failures.isEmpty()) {
- return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
- }
- //保存
- List<TBStockInfoEntity> tBStockInfoList = tBGoodsInfoPage.getTBStockInfoList();
- List<TBPriceInfoEntity> tBPriceInfoList = tBGoodsInfoPage.getTBPriceInfoList();
- TBGoodsInfoEntity tBGoodsInfo = new TBGoodsInfoEntity();
- try {
- MyBeanUtils.copyBeanNotNull2Bean(tBGoodsInfo, tBGoodsInfoPage);
- } catch (Exception e) {
- logger.info(e.getMessage());
- }
- tBGoodsInfoService.updateMain(tBGoodsInfo, tBStockInfoList, tBPriceInfoList, tBGoodsInfoPage.getTBRelatedUnitPriceInfoList());
- //按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) {
- TBGoodsInfoEntity tBGoodsInfo = tBGoodsInfoService.get(TBGoodsInfoEntity.class, id);
- tBGoodsInfoService.delMain(tBGoodsInfo);
- }
- /**
- * 启用
- *
- * @author zhijia.wang
- */
- @RequestMapping(params = "enableGoodInfo")
- @ResponseBody
- public AjaxJson enableGoodInfo(String id, HttpServletRequest req) {
- AjaxJson j = new AjaxJson();
- String message = null;
- TBGoodsInfoEntity goodInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, id);
- try {
- goodInfo.setStatus(Globals.Enabled.toString());
- tBGoodsInfoService.updateEntitie(goodInfo);
- message = "货品信息:" + goodInfo.getGoodsName() + "启用成功!";
- systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
- } catch (Exception e) {
- message = "操作失败!";
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 停用
- *
- * @author zhijia.wang
- */
- @RequestMapping(params = "disableGoodInfo")
- @ResponseBody
- public AjaxJson disableGoodInfo(String id, HttpServletRequest req) {
- AjaxJson j = new AjaxJson();
- String message = null;
- TBGoodsInfoEntity goodInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, id);
- try {
- goodInfo.setStatus(Globals.Disabled.toString());
- tBGoodsInfoService.updateEntitie(goodInfo);
- message = "货品信息:" + goodInfo.getGoodsName() + "停用成功!";
- systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
- } catch (Exception e) {
- message = "操作失败!";
- }
- j.setMsg(message);
- return j;
- }
- @RequestMapping(params = "selectRelatedUnit")
- public ModelAndView selectRelatedUnit(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
- return new ModelAndView("cn/com/lzt/goodsinfo/selectRelatedUnit");
- }
- @RequestMapping(params = "selectRelatedUnitDatagrid")
- public void selectRelatedUnitDatagrid(TBGoodsInfoEntity goodsInfoEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- String hql1 = "from TBGoodsRelatedUnitPriceEntity where 1 = 1 AND gOODS_ID =? ";
- List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoEntityList = systemService.findHql(hql1, goodsInfoEntity.getId());
- dataGrid.setResults(tBRelatedUnitPriceInfoEntityList);
- dataGrid.setTotal(tBRelatedUnitPriceInfoEntityList.size());
- TagUtil.datagrid(response, dataGrid);
- }
- }
|