package com.matrix.system.hive.action;
|
|
|
import com.matrix.core.anotations.RemoveRequestToken;
|
import com.matrix.core.anotations.SaveRequestToken;
|
import com.matrix.core.constance.MatrixConstance;
|
import com.matrix.core.exception.GlobleException;
|
import com.matrix.core.pojo.AjaxResult;
|
import com.matrix.core.pojo.PaginationVO;
|
import com.matrix.core.tools.DateUtil;
|
import com.matrix.core.tools.WebUtil;
|
import com.matrix.core.tools.excl.ExcelSheetPO;
|
import com.matrix.core.tools.excl.ExcelUtil;
|
import com.matrix.core.tools.excl.ExcelVersion;
|
import com.matrix.system.common.bean.SysUsers;
|
import com.matrix.system.common.tools.ResponseHeadUtil;
|
import com.matrix.system.constance.Dictionary;
|
import com.matrix.system.hive.action.util.QueryUtil;
|
import com.matrix.system.hive.bean.SysInstoreDetail;
|
import com.matrix.system.hive.bean.SysInstoreInfo;
|
import com.matrix.system.hive.dao.SysInstoreDetailDao;
|
import com.matrix.core.tools.DateUtil;
|
import com.matrix.system.hive.plugin.util.MoneyUtil;
|
import com.matrix.system.hive.service.CodeService;
|
import com.matrix.system.hive.service.SysInstoreInfoService;
|
import com.matrix.system.hive.service.SysStoreInfoService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.ModelMap;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.io.OutputStream;
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLDecoder;
|
import java.net.URLEncoder;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 入库单
|
*
|
* @author jiangyouyao
|
* @date 2016-07-17
|
*/
|
@Controller
|
@RequestMapping(value = "admin/instore")
|
public class InstoreInfoController extends BaseController {
|
@Resource
|
private SysInstoreInfoService currentService;
|
|
@Autowired
|
private SysInstoreDetailDao instoreDetailDao;
|
|
@Resource
|
private SysStoreInfoService sysStoreInfoService;
|
@Resource
|
private CodeService codeService;
|
|
|
/**
|
* 列表显示
|
*/
|
@RequestMapping(value = "/showList")
|
public @ResponseBody
|
AjaxResult showList(SysInstoreInfo sysInstoreInfo, PaginationVO pageVo) {
|
QueryUtil.setQueryLimit(sysInstoreInfo);
|
return showList(currentService, sysInstoreInfo, pageVo);
|
}
|
|
/**
|
* 新增或修改页面
|
*/
|
@RequestMapping(value = "/addOrModify")
|
@RemoveRequestToken
|
public @ResponseBody
|
AjaxResult addOrModify(SysInstoreInfo sysInstoreInfo) {
|
SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
|
sysInstoreInfo.setShopId(users.getShopId());
|
sysInstoreInfo.setCompanyId(users.getCompanyId());
|
if (sysInstoreInfo.getId() != null) {
|
|
return modify(currentService, sysInstoreInfo, "入库单");
|
} else {
|
return add(currentService, sysInstoreInfo, "入库单");
|
}
|
}
|
|
@RequestMapping(value = "/addOrModifyJson")
|
@RemoveRequestToken
|
public @ResponseBody
|
AjaxResult addOrModifyJson(@RequestBody SysInstoreInfo sysInstoreInfo) {
|
SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
|
sysInstoreInfo.setShopId(users.getShopId());
|
sysInstoreInfo.setCompanyId(users.getCompanyId());
|
if (sysInstoreInfo.getId() != null) {
|
|
return modify(currentService, sysInstoreInfo, "入库单");
|
} else {
|
sysInstoreInfo.setMakingmanName(users.getSuName());
|
sysInstoreInfo.setMakingmanId(users.getSuId());
|
return add(currentService, sysInstoreInfo, "入库单");
|
}
|
}
|
|
|
/**
|
* 进入修改界面
|
*/
|
@RequestMapping(value = "/editForm")
|
@SaveRequestToken
|
public String editForm(Long id) {
|
SysInstoreInfo sysInstoreInfo;
|
if (id != null) {
|
sysInstoreInfo = currentService.findById(id);
|
List<SysInstoreDetail> sysInstoreDetails = instoreDetailDao.selectByOrderId(id);
|
sysInstoreInfo.setInstoreDetails(sysInstoreDetails);
|
WebUtil.getRequest().setAttribute("obj", sysInstoreInfo);
|
}
|
return "admin/hive/instore/instoreinfo-form";
|
}
|
|
@RequestMapping(value = "/findById")
|
@ResponseBody
|
public AjaxResult findById(Long id) {
|
SysInstoreInfo sysInstoreInfo = currentService.findById(id);
|
List<SysInstoreDetail> sysInstoreDetails = instoreDetailDao.selectByOrderId(id);
|
sysInstoreInfo.setInstoreDetails(sysInstoreDetails);
|
AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功");
|
ajaxResult.putInMap("obj", sysInstoreInfo);
|
return ajaxResult;
|
}
|
|
|
/**
|
* 删除
|
*/
|
@RequestMapping(value = "/del")
|
public @ResponseBody
|
AjaxResult del(String keys) {
|
|
return remove(currentService, keys);
|
}
|
|
|
/**
|
* 进入查看页面
|
*/
|
@RequestMapping(value = "/lookInfo")
|
public String lookInfo(Long id) {
|
SysInstoreInfo sysInstoreInfo;
|
if (id != null) {
|
sysInstoreInfo = currentService.findById(id);
|
|
List<SysInstoreDetail> sysInstoreDetails = instoreDetailDao.selectByOrderId(id);
|
sysInstoreInfo.setInstoreDetails(sysInstoreDetails);
|
|
int count = 0;
|
double money = 0.0;
|
for (SysInstoreDetail detail : sysInstoreDetails) {
|
count += detail.getAmount();
|
money = MoneyUtil.add(money, detail.getPriceTotal());
|
}
|
WebUtil.getRequest().setAttribute("count", count);
|
WebUtil.getRequest().setAttribute("money", money);
|
WebUtil.getRequest().setAttribute("obj", sysInstoreInfo);
|
}
|
return "admin/hive/instore/instoreinfo-look";
|
}
|
|
/**
|
* 进入审核页面
|
*/
|
@RequestMapping(value = "/checkInfo")
|
public String checkInfo(Long id) {
|
SysInstoreInfo sysInstoreInfo;
|
if (id != null) {
|
sysInstoreInfo = currentService.findById(id);
|
List<SysInstoreDetail> sysInstoreDetails = instoreDetailDao.selectByOrderId(id);
|
sysInstoreInfo.setInstoreDetails(sysInstoreDetails);
|
WebUtil.getRequest().setAttribute("obj", sysInstoreInfo);
|
}
|
return "admin/hive/instore/instoreinfo-check";
|
}
|
|
/**
|
* 审核
|
*/
|
@RequestMapping(value = "/check")
|
public @ResponseBody
|
AjaxResult check(SysInstoreInfo sysInstoreInfo) {
|
|
int i = currentService.check(sysInstoreInfo);
|
if (i > 0) {
|
return new AjaxResult(AjaxResult.STATUS_SUCCESS, "审核成功");
|
} else {
|
return new AjaxResult(AjaxResult.STATUS_SUCCESS, "审核失败");
|
}
|
|
}
|
|
/**
|
* 撤销审核
|
*/
|
@RequestMapping(value = "/unCheck")
|
public @ResponseBody
|
AjaxResult unCheck(SysInstoreInfo sysInstoreInfo) {
|
|
int i = currentService.unCheck(sysInstoreInfo);
|
if (i > 0) {
|
return new AjaxResult(AjaxResult.STATUS_SUCCESS, "撤销成功");
|
} else {
|
return new AjaxResult(AjaxResult.STATUS_SUCCESS, "撤销失败");
|
}
|
|
}
|
|
|
/**
|
* 不予审核
|
*/
|
@RequestMapping(value = "/addcheckremark")
|
public @ResponseBody
|
AjaxResult addcheckremark(SysInstoreInfo sysInstoreInfo) {
|
|
//1.判断是否有修改的权限
|
SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
|
// if (user.getRoleName().contains(Dictionary.USER_ROLE_PLZG) || user.getRoleName().contains(Dictionary.USER_ROLE_CCZG)) {
|
//2.去数据库判断该单的状态,如果审核通过不能修改
|
SysInstoreInfo checkInstoreInfo = currentService.findById(sysInstoreInfo.getId());
|
if (checkInstoreInfo != null && !(checkInstoreInfo.getCheckStatus().equals(Dictionary.CHECK_STATUS_DSH))) {
|
throw new GlobleException("该单据已审核通过,不可再审核!");
|
}
|
//3、满足条件则更改
|
|
sysInstoreInfo.setCheckStatus(Dictionary.CHECK_STATUS_SHWTG);
|
int count = currentService.update(sysInstoreInfo);
|
if (count > 0) {
|
return new AjaxResult(AjaxResult.STATUS_SUCCESS, null);
|
} else {
|
return new AjaxResult(AjaxResult.STATUS_SUCCESS, null);
|
}
|
// } else {
|
// throw new GlobleException("审核人必须为配料主管或者仓库主管!");
|
// }
|
}
|
|
/**
|
* @param @param model
|
* @param @param request
|
* @param @param response
|
* @param @param vipInfo
|
* @param @return 设定文件
|
* @return ModelAndView 返回类型
|
* @throws IOException
|
* @throws
|
* @author jiangyouyao
|
* @Title: report
|
* 入库单导出
|
*/
|
@RequestMapping(value = "/exportExcel")
|
public void report(ModelMap model, HttpServletRequest request, HttpServletResponse response, SysInstoreInfo sysInstoreInfo) throws IOException {
|
|
try {
|
if (sysInstoreInfo.getCheckStatus() != null && !"".equals(sysInstoreInfo.getCheckStatus())) {
|
sysInstoreInfo.setCheckStatus(URLDecoder.decode(sysInstoreInfo.getCheckStatus(), "UTF-8"));
|
}
|
if (sysInstoreInfo.getInstoreType() != null && !"".equals(sysInstoreInfo.getInstoreType())) {
|
sysInstoreInfo.setInstoreType(URLDecoder.decode(sysInstoreInfo.getInstoreType(), "UTF-8"));
|
}
|
} catch (UnsupportedEncodingException e1) {
|
e1.printStackTrace();
|
}
|
List<ExcelSheetPO> res = new ArrayList<>();
|
ExcelSheetPO orderSheet = new ExcelSheetPO();
|
String title = "入库单信息";
|
orderSheet.setSheetName(title);
|
orderSheet.setTitle(title);
|
String[] header = {"单号", "日期", "总价", "制单人", "审核人", "入库仓库", "往来单位", "审核状态", "审核意见", "备注"};
|
orderSheet.setHeaders(header);
|
QueryUtil.setQueryLimit(sysInstoreInfo);
|
List<SysInstoreInfo> dataList = currentService.findInPage(sysInstoreInfo, null);
|
List<List<Object>> list = new ArrayList<>();
|
if (dataList.size() > 0) {
|
for (SysInstoreInfo item : dataList) {
|
List<Object> temp = new ArrayList<>();
|
temp.add(item.getInstoreId());
|
temp.add(DateUtil.dateToString(item.getInstoreDate(), DateUtil.DATE_FORMAT_MM));
|
temp.add(item.getSumall());
|
temp.add(item.getMakingmanName());
|
temp.add(item.getAppmanName());
|
temp.add(item.getStoreName());
|
temp.add(item.getSupplierName());
|
temp.add(item.getCheckStatus());
|
temp.add(item.getAppRemark());
|
temp.add(item.getRemark());
|
list.add(temp);
|
}
|
}
|
orderSheet.setDataList(list);
|
res.add(orderSheet);
|
response = ResponseHeadUtil.setExcelHead(response);
|
response.setHeader("Content-Disposition",
|
"attachment;filename=" + URLEncoder.encode(title + DateUtil.getTimeMark() + ".xlsx".trim(), "UTF-8"));
|
OutputStream os = response.getOutputStream();
|
ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true);
|
|
|
}
|
}
|