package com.jeecg.ldcgoodsapp.controller;
import com.jeecg.decmain.entity.DecMainEntity;
import com.jeecg.demo.entity.TSDocument;
import com.jeecg.ldccommonstate.service.LdcCommonStateServiceI;
import com.jeecg.ldcgoods.entity.LdcGoodsEntity;
import com.jeecg.ldcgoods.entity.LdcGoodsLogEntity;
import com.jeecg.ldcgoodsapp.entity.LdcGoodsAppEntity;
import com.jeecg.ldcgoodsapp.service.LdcGoodsAppServiceI;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.text.SimpleDateFormat;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
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.common.TreeChildCount;
import org.jeecgframework.core.common.model.common.UploadFile;
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.DateUtils;
import org.jeecgframework.core.util.MyClassLoader;
import org.jeecgframework.core.util.ReflectHelper;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.core.util.oConvertUtils;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.system.pojo.base.TSAttachment;
import org.jeecgframework.web.system.pojo.base.TSDepart;
import org.jeecgframework.web.system.pojo.base.TSType;
import org.jeecgframework.web.system.pojo.base.TSTypegroup;
import org.jeecgframework.web.system.pojo.base.TSUser;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.core.util.MyBeanUtils;
import java.io.OutputStream;
import org.jeecgframework.core.util.BrowserUtils;
import org.jeecgframework.poi.excel.ExcelExportUtil;
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.TemplateExportParams;
import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.jeecgframework.core.util.ResourceUtil;
import java.io.IOException;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.util.Map;
import java.util.HashMap;
import org.jeecgframework.core.util.ExceptionUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
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.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.jeecgframework.core.beanvalidator.BeanValidators;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.net.URI;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.jwt.util.GsonUtil;
import org.jeecgframework.jwt.util.ResponseMessage;
import org.jeecgframework.jwt.util.Result;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
* @Title: Controller
* @Description: ldc_goods_app
* @author onlineGenerator
* @date 2020-05-28 18:25:21
* @version V1.0
*
*/
@Api(value="LdcGoodsApp",description="ldc_goods_app",tags="ldcGoodsAppController")
@Controller
@RequestMapping("/ldcGoodsAppController")
public class LdcGoodsAppController extends BaseController {
/**
* Logger for this class
*/
private static final Logger logger = Logger.getLogger(LdcGoodsAppController.class);
@Autowired
private LdcGoodsAppServiceI ldcGoodsAppService;
@Autowired
private SystemService systemService;
@Autowired
private Validator validator;
@Autowired
private LdcCommonStateServiceI ldcCommonStateService;
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* ldc_goods_app列表 页面跳转
*
* @return
*/
@RequestMapping(params = "list")
public ModelAndView list(HttpServletRequest request) {
String num = request.getParameter("num");
request.setAttribute("num", request.getParameter("num"));
return new ModelAndView("com/jeecg/ldcgoodsapp/ldcGoodsAppList");
}
/**
* easyui AJAX请求数据
*
* @param request
* @param response
* @param dataGrid
* @param user
*/
@RequestMapping(params = "datagrid")
public void datagrid(LdcGoodsAppEntity ldcGoodsApp,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
CriteriaQuery cq = new CriteriaQuery(LdcGoodsAppEntity.class, dataGrid);
String num = request.getParameter("num");
int cnt = 0;
//查询条件组装器
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, ldcGoodsApp, request.getParameterMap());
try{
if("2".equals(num)){
cnt = 1;
List<Integer> sss = new ArrayList<Integer>();
sss.add(1);
sss.add(4);
Integer[] strings = new Integer[sss.size()];
cq.in("goodsState", sss.toArray(strings));
}else if("3".equals(num)){
cnt = 2;
cq.eq("goodsState", cnt);
}else if("4".equals(num)){
cnt = 3;
cq.eq("goodsState", cnt);
}
//自定义追加查询条件
}catch (Exception e) {
throw new BusinessException(e.getMessage());
}
cq.add();
this.ldcGoodsAppService.getDataGridReturn(cq, true);
TagUtil.datagrid(response, dataGrid);
}
/**
* 删除ldc_goods_app
*
* @return
*/
@RequestMapping(params = "doDel")
@ResponseBody
public AjaxJson doDel(LdcGoodsAppEntity ldcGoodsApp, HttpServletRequest request) {
String message = null;
AjaxJson j = new AjaxJson();
ldcGoodsApp = systemService.getEntity(LdcGoodsAppEntity.class, ldcGoodsApp.getId());
message = "删除成功";
try{
ldcGoodsAppService.delete(ldcGoodsApp);
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;
}
/**
* 批量删除ldc_goods_app
*
* @return
*/
@RequestMapping(params = "doBatchDel")
@ResponseBody
public AjaxJson doBatchDel(String ids,HttpServletRequest request){
String message = null;
AjaxJson j = new AjaxJson();
message = "删除成功";
try{
for(String id:ids.split(",")){
LdcGoodsAppEntity ldcGoodsApp = systemService.getEntity(LdcGoodsAppEntity.class,
id
);
ldcGoodsAppService.delete(ldcGoodsApp);
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;
}
/**
* 添加ldc_goods_app
*
* @param ids
* @return
*/
@RequestMapping(params = "doAdd")
@ResponseBody
public AjaxJson doAdd(LdcGoodsAppEntity ldcGoodsApp, HttpServletRequest request) {
String message = null;
AjaxJson j = new AjaxJson();
message = "添加成功";
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");//设置日期格式
String sysdateStr = df.format(new Date());
String sql = "";
String gdCode = "";
try{
sql = " select gd_code from ldc_goods_app ";
List<Map<String, Object>> gdCodeList = jdbcTemplate.queryForList(sql);
if(gdCodeList!=null && gdCodeList.size()>0) {
String maxStr = "1001";
for(int i=0;i<gdCodeList.size();i++){
String str = gdCodeList.get(i).get("gd_code").toString();
String substr = str.substring(2, 10);
if(substr.equals(sysdateStr)){
String substr1 = str.substring(10);
if(Integer.parseInt(maxStr)<Integer.parseInt(substr1)){
maxStr=substr1;
}
}
}
gdCode = "GL"+sysdateStr+(Integer.parseInt(maxStr)+1);
}else{
gdCode = "GL"+sysdateStr+"1001";
}
ldcGoodsApp.setGoodsCtime(new Date());
ldcGoodsApp.setGdCode(gdCode);
ldcGoodsApp.setGoodsState(1);
ldcGoodsAppService.save(ldcGoodsApp);
ldcCommonStateService.goods_check(ldcGoodsApp.getId(),"gladd");
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;
}
/**
* 更新ldc_goods_app
*
* @param ids
* @return
*/
@RequestMapping(params = "doUpdate")
@ResponseBody
public AjaxJson doUpdate(LdcGoodsAppEntity ldcGoodsApp, HttpServletRequest request) {
String message = null;
AjaxJson j = new AjaxJson();
message = "更新成功";
LdcGoodsAppEntity t = ldcGoodsAppService.get(LdcGoodsAppEntity.class, ldcGoodsApp.getId());
try {
MyBeanUtils.copyBeanNotNull2Bean(ldcGoodsApp, t);
t.setGoodsUptime(new Date());
ldcGoodsAppService.saveOrUpdate(t);
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;
}
/**
* ldc_goods_app新增页面跳转
*
* @return
*/
@RequestMapping(params = "goAdd")
public ModelAndView goAdd(LdcGoodsAppEntity ldcGoodsApp, HttpServletRequest req) {
if (StringUtil.isNotEmpty(ldcGoodsApp.getId())) {
ldcGoodsApp = ldcGoodsAppService.getEntity(LdcGoodsAppEntity.class, ldcGoodsApp.getId());
req.setAttribute("ldcGoodsAppPage", ldcGoodsApp);
}
return new ModelAndView("com/jeecg/ldcgoodsapp/ldcGoodsApp-add");
}
/**
* ldc_goods_app编辑页面跳转
*
* @return
*/
@RequestMapping(params = "goUpdate")
public ModelAndView goUpdate(LdcGoodsAppEntity ldcGoodsApp, HttpServletRequest req) {
if (StringUtil.isNotEmpty(ldcGoodsApp.getId())) {
ldcGoodsApp = ldcGoodsAppService.getEntity(LdcGoodsAppEntity.class, ldcGoodsApp.getId());
req.setAttribute("ldcGoodsAppPage", ldcGoodsApp);
}
return new ModelAndView("com/jeecg/ldcgoodsapp/ldcGoodsApp-update");
}
/**
* 导入功能跳转
*
* @return
*/
@RequestMapping(params = "upload")
public ModelAndView upload(HttpServletRequest req) {
req.setAttribute("controller_name","ldcGoodsAppController");
return new ModelAndView("common/upload/pub_excel_upload");
}
/**
* 导出excel
*
* @param request
* @param response
*/
@RequestMapping(params = "exportXls")
public String exportXls(LdcGoodsAppEntity ldcGoodsApp,HttpServletRequest request,HttpServletResponse response
, DataGrid dataGrid,ModelMap modelMap) {
CriteriaQuery cq = new CriteriaQuery(LdcGoodsAppEntity.class, dataGrid);
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, ldcGoodsApp, request.getParameterMap());
List<LdcGoodsAppEntity> ldcGoodsApps = this.ldcGoodsAppService.getListByCriteriaQuery(cq,false);
modelMap.put(NormalExcelConstants.FILE_NAME,"ldc_goods_app");
modelMap.put(NormalExcelConstants.CLASS,LdcGoodsAppEntity.class);
modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("ldc_goods_app列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
"导出信息"));
modelMap.put(NormalExcelConstants.DATA_LIST,ldcGoodsApps);
return NormalExcelConstants.JEECG_EXCEL_VIEW;
}
/**
* 导出excel 使模板
*
* @param request
* @param response
*/
@RequestMapping(params = "exportXlsByT")
public String exportXlsByT(LdcGoodsAppEntity ldcGoodsApp,HttpServletRequest request,HttpServletResponse response
, DataGrid dataGrid,ModelMap modelMap) {
modelMap.put(NormalExcelConstants.FILE_NAME,"ldc_goods_app");
modelMap.put(NormalExcelConstants.CLASS,LdcGoodsAppEntity.class);
modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("ldc_goods_app列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
"导出信息"));
modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
return NormalExcelConstants.JEECG_EXCEL_VIEW;
}
@SuppressWarnings("unchecked")
@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(1);
params.setNeedSave(true);
try {
List<LdcGoodsAppEntity> listLdcGoodsAppEntitys = ExcelImportUtil.importExcel(file.getInputStream(),LdcGoodsAppEntity.class,params);
for (LdcGoodsAppEntity ldcGoodsApp : listLdcGoodsAppEntitys) {
ldcGoodsAppService.save(ldcGoodsApp);
}
j.setMsg("文件导入成功!");
} catch (Exception e) {
j.setMsg("文件导入失败!");
logger.error(ExceptionUtil.getExceptionMessage(e));
}finally{
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return j;
}
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value="列表信息",produces="application/json",httpMethod="GET")
public ResponseMessage<List<LdcGoodsAppEntity>> list() {
List<LdcGoodsAppEntity> listLdcGoodsApps=ldcGoodsAppService.getList(LdcGoodsAppEntity.class);
return Result.success(listLdcGoodsApps);
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value="根据ID获取ldc_goods_app信息",notes="根据ID获取ldc_goods_app信息",httpMethod="GET",produces="application/json")
public ResponseMessage<?> get(@ApiParam(required=true,name="id",value="ID")@PathVariable("id") String id) {
LdcGoodsAppEntity task = ldcGoodsAppService.get(LdcGoodsAppEntity.class, id);
if (task == null) {
return Result.error("根据ID获取ldc_goods_app信息为空");
}
return Result.success(task);
}
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@ApiOperation(value="创建ldc_goods_app")
public ResponseMessage<?> create(@ApiParam(name="ldc_goods_app对象")@RequestBody LdcGoodsAppEntity ldcGoodsApp, UriComponentsBuilder uriBuilder) {
//调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
Set<ConstraintViolation<LdcGoodsAppEntity>> failures = validator.validate(ldcGoodsApp);
if (!failures.isEmpty()) {
return Result.error(JSONArray.toJSONString(BeanValidators.extractPropertyAndMessage(failures)));
}
//保存
try{
ldcGoodsAppService.save(ldcGoodsApp);
} catch (Exception e) {
e.printStackTrace();
return Result.error("信息保存失败");
}
return Result.success(ldcGoodsApp);
}
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@ApiOperation(value="更新ldc_goods_app",notes="更新ldc_goods_app")
public ResponseMessage<?> update(@ApiParam(name="ldc_goods_app对象")@RequestBody LdcGoodsAppEntity ldcGoodsApp) {
//调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
Set<ConstraintViolation<LdcGoodsAppEntity>> failures = validator.validate(ldcGoodsApp);
if (!failures.isEmpty()) {
return Result.error(JSONArray.toJSONString(BeanValidators.extractPropertyAndMessage(failures)));
}
//保存
try{
ldcGoodsAppService.saveOrUpdate(ldcGoodsApp);
} catch (Exception e) {
e.printStackTrace();
return Result.error("更新信息失败");
}
//按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
return Result.success("更新信息成功");
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(value="删除ldc_goods_app")
public ResponseMessage<?> delete(@ApiParam(name="id",value="ID",required=true)@PathVariable("id") String id) {
logger.info("delete[{}]" + id);
// 验证
if (StringUtils.isEmpty(id)) {
return Result.error("ID不能为空");
}
try {
ldcGoodsAppService.deleteEntityById(LdcGoodsAppEntity.class, id);
} catch (Exception e) {
e.printStackTrace();
return Result.error("删除失败");
}
return Result.success();
}
@RequestMapping(params = "gofujian")
public ModelAndView gofujian(LdcGoodsAppEntity ldcGoodsApp, HttpServletRequest req) {
String id = req.getParameter("id").toString();
if(StringUtil.isNotEmpty(id)){
ldcGoodsApp = ldcGoodsAppService.getEntity(LdcGoodsAppEntity.class, id);
req.setAttribute("ldcGoodsApp", ldcGoodsApp);
}
return new ModelAndView("com/jeecg/ldcgoodsapp/fujianList");
}
/**
* 保存文件
*
* @param document
* @return
* @throws Exception
*/
@RequestMapping(params = "saveFiles", method = RequestMethod.POST)
@ResponseBody
public AjaxJson saveFiles(HttpServletRequest request, HttpServletResponse response, TSDocument document) {
AjaxJson j = new AjaxJson();
TSUser user = ResourceUtil.getSessionUser();
Map<String, Object> attributes = new HashMap<String, Object>();
TSTypegroup tsTypegroup = systemService.getTypeGroup("fieltype", "文档分类");
TSType tsType = systemService.getType("cusfiles", "客户附件", tsTypegroup);
String documentId = oConvertUtils.getString(request.getParameter("documentId"));// 文件ID
String orderno = oConvertUtils.getString(request.getParameter("orderno"));// 文件ID
String documentTitle = oConvertUtils.getString(request.getParameter("documentTitle"));// 文件标题
String handbookid = oConvertUtils.getString(request.getParameter("handbookid"));// 手册id
if (StringUtil.isNotEmpty(documentId)) {
document.setId(documentId);
document = systemService.getEntity(TSDocument.class, documentId);
document.setDocumentTitle(documentTitle);
}
if (StringUtil.isNotEmpty(orderno)) {
document.setNote(orderno);
}
document.setFid(handbookid);
document.setTSUser(user);
document.setFtable("ld_customer");
document.setSubclassname(MyClassLoader.getPackPath(document));
document.setCreatedate(DateUtils.gettimestamp());
document.setTSType(tsType);
document.setFilesid(handbookid);
document.setftable("ld_customer");
UploadFile uploadFile = new UploadFile(request, document);
uploadFile.setCusPath("files");
// 设置weboffice转化【不设置该字段,则不做在线预览转化】
uploadFile.setSwfpath("swfpath");
document = systemService.uploadFile(uploadFile);
attributes.put("url", document.getRealpath());
attributes.put("fileKey", document.getId());
attributes.put("name", document.getAttachmenttitle());
attributes.put("viewhref", "commonController.do?objfileList&fileKey=" + document.getId());
attributes.put("delurl", "commonController.do?delObjFile&fileKey=" + document.getId());
j.setMsg("文件添加成功");
j.setAttributes(attributes);
return j;
}
@RequestMapping(params = "viewFile")
public void viewFile(HttpServletRequest request, HttpServletResponse response) {
String fileid =oConvertUtils.getString(request.getParameter("fileid"));
String subclassname = request.getParameter("subclassname");
if(oConvertUtils.isEmpty(subclassname)){
TSAttachment tsAttachment = systemService.getEntity(TSAttachment.class, fileid);
UploadFile uploadFile = new UploadFile(request, response);
//byte[] content = tsAttachment.getAttachmentcontent();
String path = tsAttachment.getRealpath();;
String extend = tsAttachment.getExtend();
String attachmenttitle = tsAttachment.getAttachmenttitle();
uploadFile.setExtend(extend);
uploadFile.setTitleField(attachmenttitle);
uploadFile.setRealPath(path);
//uploadFile.setContent(content);
//uploadFile.setView(true);
systemService.viewOrDownloadFile(uploadFile);
logger.info("--附件预览----TSAttachment---viewFile-----path--"+path);
}else{
subclassname = oConvertUtils.getString(subclassname);
Class<?> fileClass = MyClassLoader.getClassByScn(subclassname);// 自定义附件实体类
Object fileobj = systemService.getEntity(fileClass, fileid);
ReflectHelper reflectHelper = new ReflectHelper(fileobj);
UploadFile uploadFile = new UploadFile(request, response);
String contentfield = oConvertUtils.getString(request.getParameter("contentfield"), uploadFile.getByteField());
byte[] content = (byte[]) reflectHelper.getMethodValue(contentfield);
String path = oConvertUtils.getString(reflectHelper.getMethodValue("realpath"));
String extend = oConvertUtils.getString(reflectHelper.getMethodValue("extend"));
String attachmenttitle = oConvertUtils.getString(reflectHelper.getMethodValue("attachmenttitle"));
uploadFile.setExtend(extend);
uploadFile.setTitleField(attachmenttitle);
uploadFile.setRealPath(path);
uploadFile.setContent(content);
//uploadFile.setView(true);
systemService.viewOrDownloadFile(uploadFile);
logger.info("--附件预览---自定义实体类:"+subclassname+"--viewFile-----path--"+path);
}
}
@RequestMapping(params = "golook")
public ModelAndView golook(LdcGoodsAppEntity ldcGoodsApp, HttpServletRequest request) {
String type = request.getParameter("type");
String meu = request.getParameter("meu");
String btn = request.getParameter("btn");
if (StringUtil.isNotEmpty(ldcGoodsApp.getId())) {
request.setAttribute("a", ldcGoodsApp.getId());
}
request.setAttribute("type", type);
request.setAttribute("meu", meu);
request.setAttribute("btn", btn);
return new ModelAndView("com/jeecg/ldcgoodsapp/ldcCommonStateList");
}
@RequestMapping(params = "godotj")
@ResponseBody
public AjaxJson dodoif_log( HttpServletRequest req) {
String message = null;
AjaxJson j = new AjaxJson();
String id = req.getParameter("id");
String type=req.getParameter("type");
String num=req.getParameter("num");
int cnt= 0;
message = "提交成功";
try{
if("2".equals(num)){
cnt = 2;
message = "提交审核成功";
}
if(StringUtil.isNotEmpty(id)){
LdcGoodsAppEntity ldcGoodsApp = ldcGoodsAppService.getEntity(LdcGoodsAppEntity.class, id);
ldcGoodsApp.setGoodsState(cnt);
ldcGoodsAppService.saveOrUpdate(ldcGoodsApp);
ldcCommonStateService.goods_check(ldcGoodsApp.getId(),type);
}
}catch(Exception e){
e.printStackTrace();
message = "提交失败";
throw new BusinessException(e.getMessage());
}
j.setMsg(message);
return j;
}
@RequestMapping(params = "isRepeat")
@ResponseBody
public AjaxJson isRepeat(HttpServletRequest request) {
AjaxJson j = new AjaxJson();
String goodsWuliao = oConvertUtils.getString(request.getParameter("goodsWuliao"));
String goodsCode = oConvertUtils.getString(request.getParameter("goodsCode"));
String goodsHwtype = oConvertUtils.getString(request.getParameter("goodsHwtype"));
String type = oConvertUtils.getString(request.getParameter("type"));
String msg = "";
String sql="";
int cnt = 0;
String str = "";
try {
//物料号 商品编码 类型 存在
sql = "select count(1) from ldc_goods_log a where a.goods_Code = '"+goodsCode+"' and a.goods_Wuliao = '"+goodsWuliao+"' and a.goods_Hwtype = '"+goodsHwtype+"' and a.goods_flag != '2' " ;
cnt = jdbcTemplate.queryForInt(sql);
if(cnt>0){
msg = "该类型下此物料号已存在";
j.setMsg(msg);
j.setSuccess(false);
return j;
}
//继续校验 物料号 商品编码
sql = "select count(1) from ldc_goods_log a where a.goods_Wuliao = '"+goodsWuliao+"' and a.GOODS_FLAG != '2'";
cnt = jdbcTemplate.queryForInt(sql);
if(cnt>0){
sql = "select goods_Code from ldc_goods_log a where a.goods_Wuliao = '"+goodsWuliao+"' and a.GOODS_FLAG != '2'";
List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(sql);
for(Map<String, Object> map :queryForList){
str = map.get("goods_Code").toString();
if(!str.equals(goodsCode)){
msg = "物料号下商品编码需一致";
j.setMsg(msg);
j.setSuccess(false);
return j;
}
}
}
} catch (Exception e) {
// TODO: handle exception
}
return j;
}
@RequestMapping(params = "isRepeat_app")
@ResponseBody
public AjaxJson isRepeat_app(HttpServletRequest request) {
AjaxJson j = new AjaxJson();
String goodsWuliao = oConvertUtils.getString(request.getParameter("goodsWuliao"));
String goodsCode = oConvertUtils.getString(request.getParameter("goodsCode"));
String goodsHwtype = oConvertUtils.getString(request.getParameter("goodsHwtype"));
String type = oConvertUtils.getString(request.getParameter("type"));
String msg = "";
String sql="";
int cnt = 0;
String str = "";
try {
//物料号 商品编码 类型 存在
sql = "select count(1) from LDC_GOODS_APP a where a.goods_Code = '"+goodsCode+"' and a.goods_Wuliao = '"+goodsWuliao+"' and a.goods_Hwtype = '"+goodsHwtype+"' " ;
cnt = jdbcTemplate.queryForInt(sql);
if(cnt>0){
msg = goodsWuliao+"物料号已存在该货物类型";
j.setMsg(msg);
j.setSuccess(false);
return j;
}
//继续校验 物料号 商品编码
sql = "select count(1) from LDC_GOODS_APP a where a.goods_Wuliao = '"+goodsWuliao+"' ";
cnt = jdbcTemplate.queryForInt(sql);
if(cnt>0){
sql = "select goods_Code from LDC_GOODS_APP a where a.goods_Wuliao = '"+goodsWuliao+"' ";
List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(sql);
for(Map<String, Object> map :queryForList){
str = map.get("goods_Code").toString();
if(!str.equals(goodsCode)){
msg = goodsWuliao+"物料号下商品编码需一致";
j.setMsg(msg);
j.setSuccess(false);
return j;
}
}
}
} catch (Exception e) {
// TODO: handle exception
}
return j;
}
@RequestMapping(params = "gocheck_log")
public ModelAndView gocheck_log(LdcGoodsAppEntity ldcGoodsapp, HttpServletRequest req) {
TSUser user = ResourceUtil.getSessionUser();
if (StringUtil.isNotEmpty(ldcGoodsapp.getId())) {
ldcGoodsapp = ldcGoodsAppService.getEntity(LdcGoodsAppEntity.class, ldcGoodsapp.getId());
req.setAttribute("id",ldcGoodsapp.getId());
}
req.setAttribute("userrealname",user.getRealName());
return new ModelAndView("com/jeecg/ldcgoodsapp/ldcGoodsApp-docheck");
}
@RequestMapping(params = "docheck_log")
@ResponseBody
public AjaxJson docheck_log(String id,String status, HttpServletRequest req) {
String message = null;
TSUser user = ResourceUtil.getSessionUser();
AjaxJson j = new AjaxJson();
message = "审批成功";
try{
String content=req.getParameter("content");
//审核成功
if(status.equals("Y")) {
String goodsWuliao = "";
String goodsCode = "";
String goodsHwtype = "";
LdcGoodsAppEntity ldcGoodsapp = ldcGoodsAppService.getEntity(LdcGoodsAppEntity.class, id);
if(ldcGoodsapp.getGoodsWuliao()!=null){
goodsWuliao = ldcGoodsapp.getGoodsWuliao().toString();
}
if(ldcGoodsapp.getGoodsCode()!=null){
goodsCode = ldcGoodsapp.getGoodsCode().toString();
}
if(ldcGoodsapp.getGoodsHwtype()!=null){
goodsHwtype = ldcGoodsapp.getGoodsHwtype().toString();
}
//物料号 商品编码 类型 存在
String sql = "select count(1) from ldc_goods_log a where a.goods_Code = '"+goodsCode+"' and a.goods_Wuliao = '"+goodsWuliao+"' and a.goods_Hwtype = '"+goodsHwtype+"' and a.goods_flag != '2' " ;
int cnt = jdbcTemplate.queryForInt(sql);
if(cnt>0){
message = "该类型下此物料号已存在";
j.setMsg(message);
j.setSuccess(false);
return j;
}
//继续校验 物料号 商品编码
sql = "select count(1) from ldc_goods_log a where a.goods_Wuliao = '"+goodsWuliao+"' and a.GOODS_FLAG != '2'";
cnt = jdbcTemplate.queryForInt(sql);
if(cnt>0){
sql = "select goods_Code from ldc_goods_log a where a.goods_Wuliao = '"+goodsWuliao+"' and a.GOODS_FLAG != '2'";
List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(sql);
for(Map<String, Object> map :queryForList){
String str = map.get("goods_Code").toString();
if(!str.equals(goodsCode)){
message = "物料号下商品编码需一致";
j.setMsg(message);
j.setSuccess(false);
return j;
}
}
}
LdcGoodsAppEntity ldcGoodsapp1 = ldcGoodsAppService.getEntity(LdcGoodsAppEntity.class, id);
ldcGoodsapp1.setGoodsState(3);
ldcGoodsapp1.setGoodsAuditcontent(content);
ldcGoodsAppService.saveOrUpdate(ldcGoodsapp1);
ldcCommonStateService.goods_check(id,"glqd");
String uuid = UUID.randomUUID().toString().replaceAll("-","");
sql = "insert into ldc_goods_log (
" +
"id,goods_ljcode,goods_type,goods_en,goods_zh,
" +
"goods_code,goods_comment1,goods_operator,goods_check,goods_audit,
" +
"goods_law,goods_licence,goods_content,goods_ctime,goods_uptime,
" +
"goods_state,goods_flag,goods_auditcontent,goods_wuliao,goods_cjunit,
" +
"goods_fdunit,goods_deunit,goods_ieflag,goods_liscense,goods_rules,
" +
"goods_comment,test,goods_place,wtotax,gobacktax,
" +
"goodsCjunit_value,goodsFdunit_value,goodsDeunit_value,addtax,favoredtax,
" +
"provisionaltax,specialCertifficate,inspection,inspectionValue,specialCertificate,
" +
"isDangerous,goods_hwtype,G_ENG_MODEL,ENT_UNIT,FACTOR_0,FACTOR_1,
" +
"FACTOR_2,DEC_PRICE,NET_WT,FACTOR_WT,bond_MODE,
" +
"DUTY_RATE,MERGE_FLAG,goods_factory,goods_version,goods_country,
" +
"goods_version_date,goods_customer,CIQ_FLAG,curr,create_name,create_by,create_date,update_name,update_by,update_date,sys_org_code,sys_company_code
" +
")
" +
"select '"+uuid+"',goods_ljcode,'新增',goods_en,goods_zh,
" +
"goods_code,goods_comment1,goods_operator,goods_check,goods_audit,
" +
"goods_law,goods_licence,goods_content,goods_ctime,goods_uptime,
" +
"'0','0',goods_auditcontent,goods_wuliao,goods_cjunit,
" +
"goods_fdunit,goods_deunit,goods_ieflag,goods_liscense,goods_rules,
" +
"goods_comment,test,goods_place,wtotax,gobacktax,
" +
"goodsCjunit_value,goodsFdunit_value,goodsDeunit_value,addtax,favoredtax,
" +
"provisionaltax,specialCertifficate,inspection,inspectionValue,specialCertificate,
" +
"isDangerous,goods_hwtype,G_ENG_MODEL,ENT_UNIT,FACTOR_0,FACTOR_1,
" +
"FACTOR_2,DEC_PRICE,NET_WT,FACTOR_WT,bond_MODE,
" +
"DUTY_RATE,MERGE_FLAG,goods_factory,goods_version,goods_country,
" +
"goods_version_date,goods_customer,CIQ_FLAG,curr,create_name,create_by,create_date,update_name,update_by,update_date,sys_org_code,sys_company_code " +
" from ldc_goods_app "+
" where id = '"+id+"'";
jdbcTemplate.update(sql);
ldcCommonStateService.goods_check(uuid,"gladdwl");
}else if(status.equals("N")){
LdcGoodsAppEntity ldcGoodsapp1 = ldcGoodsAppService.getEntity(LdcGoodsAppEntity.class, id);
ldcGoodsapp1.setGoodsState(4);
ldcGoodsapp1.setGoodsAuditcontent(content);
ldcGoodsAppService.saveOrUpdate(ldcGoodsapp1);
ldcCommonStateService.goods_check(id,"glqd1");
}
//ldcCommonStateService.goods_check(ldcGoods.getId());
}catch(Exception e){
e.printStackTrace();
message = "提交失败";
throw new BusinessException(e.getMessage());
}
j.setMsg(message);
return j;
}
}