use of com.fruit.manage.model.ProcurementPlanDetail in project fruit-manage by liuzhaozhao.
the class PlanDetailController method updatePPlanDetailTwo.
/**
* 修改采购计划
*/
public void updatePPlanDetailTwo() {
ProcurementPlanDetail procurementPlanDetail = getModel(ProcurementPlanDetail.class, "", true);
procurementPlanDetail.update();
renderJson(new ArrayList<>(1).add(0));
}
use of com.fruit.manage.model.ProcurementPlanDetail in project fruit-manage by liuzhaozhao.
the class PlanController method exportPPlan.
/**
* 根据采购计划ID导出采购计划单
*/
public void exportPPlan() {
Integer uid = getSessionAttr(Constant.SESSION_UID);
// 获取当前操作用户
User user = User.dao.findById(uid);
Date createTime = getParaToDate("createTime");
String createTimeStr = DateAndStringFormat.getStringDateShort(createTime);
String[] createTimes = new String[2];
createTimes[0] = DateAndStringFormat.getNextDay(createTimeStr, "-1") + " 12:00:00";
createTimes[1] = createTimeStr + " 11:59:59";
// 获取要导出数据
List<ProcurementPlan> planList = ProcurementPlan.dao.getExportDataByPPlanID(createTimes);
// 行头
String[] header = { "商品名", "规格名", "规格编码", "重量(斤)", "报价", "下单量", "库存量", "采购量", "采购单价", "下单备注" };
// 先执行删除操作
ProcurementPlanDetail.dao.delPPlanDetail(createTimes);
// excel表格信息
HashMap<Integer, Map<String, Object>> excelInfoList = new HashMap<>(5);
// List<String[]> listData = new ArrayList<String[]>();
String zipFileName = "file_zip_plan" + System.currentTimeMillis();
String zipFolder = CommonController.FILE_PATH + File.separator + zipFileName;
File zipFolderFile = new File(zipFolder);
if (zipFolderFile.exists()) {
zipFolderFile.mkdirs();
}
if (planList.size() < 1) {
renderErrorText("一条订单都没有");
return;
}
for (ProcurementPlan procurementPlan : planList) {
// 根据采购人分别保存信息,用来区分不同的采购采购的东西
Map<String, Object> excelInfo = excelInfoList.get(procurementPlan.get("procurement_id"));
List<Object[]> listData = null;
if (excelInfo == null) {
excelInfo = new HashMap<>(20);
excelInfoList.put(procurementPlan.get("procurement_id"), excelInfo);
excelInfo.put("path", zipFolder);
excelInfo.put("fileName", "file_" + UUID.randomUUID().toString().replaceAll("-", "") + ".xlsx");
excelInfo.put("title", "采购计划表");
excelInfo.put("createBy", procurementPlan.get("procurement_name"));
excelInfo.put("header", header);
excelInfo.put("listData", new ArrayList<Object[]>());
listData = (List<Object[]>) excelInfo.get("listData");
} else {
listData = (List<Object[]>) excelInfo.get("listData");
}
Object[] str = new Object[header.length];
Integer productId = procurementPlan.get("productId");
// 商品名
str[0] = procurementPlan.get("productName");
// 规格名
str[1] = procurementPlan.get("productStandardName");
// 规格编号
str[2] = procurementPlan.get("productStandardID");
// 水果重量
str[3] = procurementPlan.get("fruitWeight");
// 报价
str[4] = procurementPlan.get("sellPrice");
str[5] = procurementPlan.get("purchaseNum");
str[6] = procurementPlan.get("inventoryNum");
str[7] = procurementPlan.get("procurementNum");
str[8] = procurementPlan.get("procurementPrice");
// TODO 需要改成订单备注
str[9] = procurementPlan.get("procurementRemark");
listData.add(str);
ProcurementPlanDetail procurementPlanDetail = new ProcurementPlanDetail();
procurementPlanDetail.setProductId(productId);
procurementPlanDetail.setProductStandardId(procurementPlan.get("productStandardID"));
procurementPlanDetail.setProcurementId(uid);
procurementPlanDetail.setProductName(procurementPlan.get("productName"));
procurementPlanDetail.setProductStandardName(procurementPlan.get("productStandardName"));
procurementPlanDetail.setSellPrice(procurementPlan.get("sellPrice"));
procurementPlanDetail.setInventoryNum(Integer.parseInt(procurementPlan.get("inventoryNum") + ""));
procurementPlanDetail.setProcurementNum(Integer.parseInt(procurementPlan.get("procurementNum") + ""));
procurementPlanDetail.setProductStandardNum(Integer.parseInt(procurementPlan.get("productStandardNum") + ""));
procurementPlanDetail.setProcurementNeedPrice(BigDecimal.valueOf(procurementPlan.get("procurementNeedPrice")));
procurementPlanDetail.setProcurementTotalPrice(BigDecimal.valueOf(procurementPlan.get("procurementTotalPrice")));
procurementPlanDetail.setOrderRemark(procurementPlan.get("orderRemark"));
procurementPlanDetail.setProcurementRemark(procurementPlan.get("procurementRemark"));
procurementPlanDetail.setCreateTime(createTime);
procurementPlanDetail.setUpdateTime(new Date());
procurementPlanDetail.save();
}
// 保存路径
// String savePath = getRequest().getSession().getServletContext().getRealPath("static/excel");
// System.out.println("\n" + savePath);
// String fpath = getSession().getServletContext().getRealPath("static/excel");
// String fileName = "file_" + UUID.randomUUID().toString().replaceAll("-", "") + ".xlsx";
// System.out.println(fpath + "\n");
// Map map = new HashMap(12);
// map.put("path", savePath);
// map.put("fileName", fileName);
// map.put("title", "采购计划表");
// map.put("createBy", user.getName());
// map.put("header", header);
// map.put("listData", listData);
ArrayList<File> files = new ArrayList<>();
for (Integer integer : excelInfoList.keySet()) {
Map<String, Object> stringObjectMap = excelInfoList.get(integer);
String file = null;
try {
file = ExcelCommon.createExcelModul(stringObjectMap);
} catch (ExcelException e) {
renderErrorText(e.getMessage());
}
files.add(new File(file));
}
String zipName = zipFileName + ".zip";
boolean b = fileToZip(zipFolder, CommonController.FILE_PATH, zipFileName);
HashMap<Object, Object> objectObjectHashMap = new HashMap<>(1);
objectObjectHashMap.put("zipName", zipName);
renderJson(objectObjectHashMap);
}
use of com.fruit.manage.model.ProcurementPlanDetail in project fruit-manage by liuzhaozhao.
the class PlanDetailController method updatePPlanDetail.
/**
* 根据时间字段更新采购计划
*/
@Before(Tx.class)
public void updatePPlanDetail() {
Integer uid = getSessionAttr(Constant.SESSION_UID);
// 获取当前操作用户
User user = User.dao.findById(uid);
Date createTime = getParaToDate("createTime");
String createTimeStr = DateAndStringFormat.getStringDateShort(createTime);
String[] createTimes = new String[2];
createTimes[0] = DateAndStringFormat.getNextDay(createTimeStr, "-1") + " 12:00:00";
createTimes[1] = createTimeStr + " 11:59:59";
// 获取要导出数据
List<ProcurementPlan> planList = ProcurementPlan.dao.getExportDataByPPlanID(createTimes);
// 先执行删除操作
// ProcurementPlanDetail.dao.delPPlanDetail(createTimes);
List<String> list = new ArrayList<>();
try {
for (ProcurementPlan procurementPlan : planList) {
ProcurementPlanDetail procurementPlanDetail2 = ProcurementPlanDetail.dao.getPPlanDetailByPSID(procurementPlan.get("productStandardID"), createTimes, null);
// 如果采购计划不存在就新增
if (procurementPlanDetail2 == null) {
Integer productId = procurementPlan.get("productId");
ProcurementPlanDetail procurementPlanDetail = new ProcurementPlanDetail();
procurementPlanDetail.setProductId(productId);
procurementPlanDetail.setProductStandardId(procurementPlan.get("productStandardID"));
procurementPlanDetail.setProcurementId(uid);
procurementPlanDetail.setProductName(procurementPlan.get("productName"));
procurementPlanDetail.setProductStandardName(procurementPlan.get("productStandardName"));
procurementPlanDetail.setSellPrice(procurementPlan.get("sellPrice"));
procurementPlanDetail.setInventoryNum(Integer.parseInt(procurementPlan.get("inventoryNum") + ""));
procurementPlanDetail.setProcurementNum(Integer.parseInt(procurementPlan.get("procurementNum") + ""));
procurementPlanDetail.setProductStandardNum(Integer.parseInt(procurementPlan.get("productStandardNum") + ""));
procurementPlanDetail.setProcurementNeedPrice(BigDecimal.valueOf(procurementPlan.get("procurementNeedPrice")));
procurementPlanDetail.setProcurementTotalPrice(BigDecimal.valueOf(procurementPlan.get("procurementTotalPrice")));
procurementPlanDetail.setOrderRemark(procurementPlan.get("orderRemark"));
procurementPlanDetail.setProcurementRemark(procurementPlan.get("procurementRemark"));
procurementPlanDetail.setCreateTime(createTime);
procurementPlanDetail.setUpdateTime(new Date());
procurementPlanDetail.save();
} else {
procurementPlanDetail2.setProductStandardNum(Integer.parseInt(procurementPlan.get("productStandardNum") + ""));
procurementPlanDetail2.setUpdateTime(new Date());
procurementPlanDetail2.update();
}
}
// 订单日志修改为1(被统计过)
ProcurementPlan.dao.updateOrderLog(createTimes);
list.add("0");
} catch (Exception e) {
list.add("1");
}
renderJson(list);
}
use of com.fruit.manage.model.ProcurementPlanDetail in project fruit-manage by liuzhaozhao.
the class PlanDetailController method uploaderExcel.
public void uploaderExcel() {
// UploadFile uploadFile=getFile("file");
try {
String fileName = getPara("fileName");
String filePath = CommonController.FILE_PATH + File.separator + fileName;
ExcelRd excelRd = new ExcelRd(filePath);
excelRd.setStartRow(1);
excelRd.setStartCol(0);
ExcelRdTypeEnum[] types = { ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.STRING, ExcelRdTypeEnum.STRING, ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.DOUBLE, ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.STRING };
// 指定每列的类型
excelRd.setTypes(types);
List<ExcelRdRow> rows = null;
try {
rows = excelRd.analysisXlsx();
} catch (ExcelRdException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Iterator<ExcelRdRow> iterator = rows.iterator();
Integer count = 0;
String[] createTimes = new String[2];
Map<Integer, List<Integer>> map = new HashMap<>(12);
while (iterator.hasNext()) {
ExcelRdRow next = iterator.next();
List<Object> row = next.getRow();
count++;
if (count == 1) {
String createTimeStr = ((String) row.get(0)).split(" ")[0].substring(5);
createTimes[0] = DateAndStringFormat.getNextDay(createTimeStr, "-1") + " 12:00:00";
createTimes[1] = createTimeStr + " 11:59:59";
}
if (count > 2) {
boolean flag = false;
ProcurementPlanDetail procurementPlanDetail = ProcurementPlanDetail.dao.getPPlanDetailByPSID((Integer) row.get(0), createTimes, null);
if (procurementPlanDetail != null) {
List<Integer> userIDs = map.get(row.get(0));
if (userIDs != null) {
for (int i = 0; i < userIDs.size(); i++) {
Integer userID = userIDs.get(i);
if (userID != null && userID != (int) row.get(5)) {
flag = true;
userIDs.add((int) row.get(5));
map.put((int) row.get(0), userIDs);
break;
} else {
userIDs.add((int) row.get(5));
map.put((int) row.get(0), userIDs);
}
}
} else {
if (userIDs == null) {
userIDs = new ArrayList<>();
}
userIDs.add((int) row.get(5));
map.put((int) row.get(0), userIDs);
}
if (flag) {
procurementPlanDetail.setId(null);
procurementPlanDetail.setProductStandardId((int) row.get(0));
procurementPlanDetail.setProductName((String) row.get(1));
procurementPlanDetail.setProductStandardName((String) row.get(2));
procurementPlanDetail.setProcurementNum((int) row.get(3));
procurementPlanDetail.setProcurementNeedPrice(new BigDecimal((Double) row.get(4)));
procurementPlanDetail.setProcurementId((int) row.get(5));
procurementPlanDetail.setProcurementRemark((String) row.get(6));
BigDecimal pNeedPrice = new BigDecimal((Double) row.get(4));
BigDecimal pNum = new BigDecimal((int) row.get(3));
procurementPlanDetail.setProcurementTotalPrice(pNeedPrice.multiply(pNum));
procurementPlanDetail.setUpdateTime(new Date());
procurementPlanDetail.save();
} else {
procurementPlanDetail.setProductStandardId((int) row.get(0));
procurementPlanDetail.setProductName((String) row.get(1));
procurementPlanDetail.setProductStandardName((String) row.get(2));
procurementPlanDetail.setProcurementNum((int) row.get(3));
procurementPlanDetail.setProcurementNeedPrice(new BigDecimal((Double) row.get(4)));
procurementPlanDetail.setProcurementId((int) row.get(5));
procurementPlanDetail.setProcurementRemark((String) row.get(6));
BigDecimal pNeedPrice = new BigDecimal((Double) row.get(4));
BigDecimal pNum = new BigDecimal((int) row.get(3));
procurementPlanDetail.setProcurementTotalPrice(pNeedPrice.multiply(pNum));
procurementPlanDetail.setUpdateTime(new Date());
procurementPlanDetail.update();
}
}
}
}
// 进行删除操作
List<ProcurementPlanDetail> procurementPlanDetails = ProcurementPlanDetail.dao.getPSIDAndPSCount(createTimes);
for (int i = 0; i < procurementPlanDetails.size(); i++) {
ProcurementPlanDetail procurementPlanDetail = procurementPlanDetails.get(i);
Integer psID = procurementPlanDetail.getProductStandardId();
Integer psCount = Integer.parseInt(procurementPlanDetail.get("pscount") + "");
List<Integer> list = map.get(psID);
// 判断导入的用户是否少了
if (list != null && list.size() < psCount) {
List<ProcurementPlanDetail> procurementPlanDetailList = ProcurementPlanDetail.dao.getPPDIDAndProcurementID(createTimes, psID);
for (int j = 0; j < procurementPlanDetailList.size(); j++) {
ProcurementPlanDetail procurementPlanDetail2 = procurementPlanDetailList.get(j);
Integer procurementId = procurementPlanDetail2.getProcurementId();
Integer id = procurementPlanDetail2.getId();
boolean isExist = false;
for (int k = 0; k < list.size(); k++) {
if (procurementId != null && procurementId.equals(list.get(k))) {
isExist = true;
}
}
if (!isExist) {
procurementPlanDetail2.deleteById(id);
}
}
}
}
renderJson(new ArrayList<>().add(0));
} catch (Exception e) {
renderJson(new ArrayList<>().add(1));
}
}
use of com.fruit.manage.model.ProcurementPlanDetail in project fruit-manage by liuzhaozhao.
the class PlanDetailController method getAllPPlanDetail.
/**
* 获取所有的采购计划
*/
public void getAllPPlanDetail() {
int pageNum = getParaToInt("pageNum", 1);
int pageSize = getParaToInt("pageSize", 10);
Map map = new HashMap();
String orderBy = getPara("prop");
// ascending为升序,其他为降序
boolean isASC = "ascending".equals(getPara("order"));
Date createTime = getParaToDate("create_time");
String createTimeStr = DateAndStringFormat.getStringDateShort(createTime);
String[] createTimes = new String[2];
createTimes[0] = DateAndStringFormat.getNextDay(createTimeStr, "-1") + " 12:00:00";
createTimes[1] = createTimeStr + " 11:59:59";
String userName = getPara("user_name");
String userPhone = getPara("user_phone");
String userID = getPara("user_id");
String productName = getPara("product_name");
String productID = getPara("product_id");
String productStandardName = getPara("product_standard_name");
String productStandardID = getPara("product_standard_id");
map.put("createTimes", createTimes);
map.put("userName", userName);
map.put("userPhone", userPhone);
map.put("userID", userID);
map.put("productName", productName);
map.put("productID", productID);
map.put("productStandardName", productStandardName);
map.put("productStandardID", productStandardID);
Page<ProcurementPlanDetail> pPlanDetailPage = ProcurementPlanDetail.dao.getPPlanDetail(pageNum, pageSize, orderBy, isASC, map);
ProcurementPlan procurementPlan = ProcurementPlan.dao.getWaitStatisticsOrderTotal(createTimes, createTimeStr);
if (pPlanDetailPage.getList() != null && pPlanDetailPage.getList().size() > 0) {
pPlanDetailPage.getList().get(0).put("waitStatisticsOrderTotal", procurementPlan.getWaitStatisticsOrderTotal());
}
renderJson(pPlanDetailPage);
}
Aggregations