invCardManageAction.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. package com.minpay.shouhuo;
  2. import com.minpay.common.bean.User;
  3. import com.minpay.common.format.IFormatService;
  4. import com.minpay.common.service.ILogService;
  5. import com.minpay.common.service.IPropertiesService;
  6. import com.minpay.common.util.CommonUtil;
  7. import com.minpay.common.util.DateUtil;
  8. import com.minpay.common.util.HttpPostUtil;
  9. import com.minpay.db.table.mapper.VmDeliveryInfMapper;
  10. import com.minpay.db.table.mapper.VmOrderDetailsMapper;
  11. import com.minpay.db.table.mapper.VmOrderInfMapper;
  12. import com.minpay.db.table.model.VmDeliveryInf;
  13. import com.minpay.db.table.model.VmOrderDetails;
  14. import com.minpay.db.table.model.VmOrderInf;
  15. import com.minpay.db.table.own.mapper.OrderManageMapper;
  16. import com.startup.minpay.frame.business.IMINAction;
  17. import com.startup.minpay.frame.business.res.MINActionResult;
  18. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  19. import com.startup.minpay.frame.data.format.MINCopyFormat;
  20. import com.startup.minpay.frame.exception.MINBusinessException;
  21. import com.startup.minpay.frame.jdbc.MINRowBounds;
  22. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  23. import com.startup.minpay.frame.service.base.Service;
  24. import com.startup.minpay.frame.session.MINSession;
  25. import com.startup.minpay.frame.target.MINAction;
  26. import com.startup.minpay.frame.target.MINComponent;
  27. import com.startup.minpay.frame.target.MINParam;
  28. import net.sf.json.JSONObject;
  29. import org.apache.commons.lang.StringUtils;
  30. import java.math.BigDecimal;
  31. import java.text.SimpleDateFormat;
  32. import java.util.*;
  33. /**
  34. * 财务管理
  35. *
  36. * @author wlm
  37. */
  38. @MINComponent
  39. public class invCardManageAction implements IMINAction {
  40. /**查询订单详情**/
  41. public final static String SELECT_ORDER_DETAIL = "selectOrderDetail";
  42. /**取货、作废**/
  43. public final static String UPDATE_ORDER_STT = "updateOrderStt";
  44. /**查询取货记录**/
  45. public final static String SELECT_PICKUP_RECORD = "selectPickupRecord";
  46. /** 收入统计 **/
  47. public final static String SELECT_INCOME_STATISTICS = "selectIncomeStatistics";
  48. /** 收入统计 **/
  49. public final static String SELECT_ALL_INCOME = "selectAllIncome";
  50. /** 销售数据 **/
  51. public final static String SELECT_SALES_DATA = "selectSalesData";
  52. /** 销售数据2 **/
  53. public final static String SELECT_ALL_SALE = "selectAllSale";
  54. /** 时间轴查询销售金额、预估利润 **/
  55. public final static String SELECT_INCOME_BYDATE = "selectIncomeBydate";
  56. /**
  57. * 时间轴查询销售金额、预估利润
  58. * @param session
  59. * @return
  60. * @throws Exception
  61. */
  62. @MINAction(value = SELECT_INCOME_BYDATE)
  63. public MINActionResult selectIncomeBydate (
  64. @MINParam(key = "dateFlag") String dateFlag,
  65. MINSession session) throws Exception {
  66. MINActionResult res = new MINActionResult();
  67. User user = session.getUser();
  68. //获取当前时间
  69. Date currentTime = new Date();
  70. String nowDate = DateUtil.format(currentTime,"yyyyMMdd");
  71. Map<String, String> m = new HashMap<String, String>();
  72. //昨天
  73. String yesDate = DateUtil.getDifferentDate(-1).substring(0,8);
  74. //本周第一天
  75. Calendar cal=Calendar.getInstance();
  76. cal.add(Calendar.WEEK_OF_MONTH, 0);
  77. cal.set(Calendar.DAY_OF_WEEK, 2);
  78. Date weekFristDate = cal.getTime();
  79. String weekDate = DateUtil.format(weekFristDate,"yyyyMMdd");
  80. //按时间查询
  81. String time = null;
  82. if("0".equals(dateFlag)) {
  83. m.put("nowDate", nowDate);
  84. Date parse = new SimpleDateFormat("yyyyMMdd").parse(nowDate);
  85. String dateString = new SimpleDateFormat("yyyy-MM-dd").format(parse);
  86. time = dateString;
  87. }else if("1".equals(dateFlag)) {
  88. m.put("yesDate", yesDate);
  89. Date parse = new SimpleDateFormat("yyyyMMdd").parse(yesDate);
  90. String dateString = new SimpleDateFormat("yyyy-MM-dd").format(parse);
  91. time = dateString;
  92. }else if("2".equals(dateFlag)) {
  93. m.put("weekDate", weekDate);
  94. Date parse = new SimpleDateFormat("yyyyMMdd").parse(weekDate);
  95. String dateString = new SimpleDateFormat("yyyy-MM-dd").format(parse);
  96. Date parseb = new SimpleDateFormat("yyyyMMdd").parse(nowDate);
  97. String dateStringb = new SimpleDateFormat("yyyy-MM-dd").format(parseb);
  98. time = dateString.concat(" 至 ").concat(dateStringb);
  99. }
  100. //查询累计收入
  101. String countIncome = Service.lookup(IMINDataBaseService.class)
  102. .getMybatisMapper(OrderManageMapper.class).selectCountIncome(m);
  103. //查询总成本价
  104. String predictIncome = Service.lookup(IMINDataBaseService.class)
  105. .getMybatisMapper(OrderManageMapper.class).selectPredictIncome(m);
  106. //查询累计收入
  107. List<Map<String, String>> mapList = Service.lookup(IMINDataBaseService.class)
  108. .getMybatisMapper(OrderManageMapper.class).selectCountIncomeb(m);
  109. String wxzfbAmout = "0";
  110. String czAmout = "0";
  111. for (int i = 0; i < mapList.size(); i++) {
  112. Map<String, String> map = mapList.get(i);
  113. String transType = map.get("transType");
  114. if(transType.equals("00")){ //充值金额
  115. czAmout = String.valueOf(map.get("amout"));
  116. }
  117. if(transType.equals("10")){ //支付金额
  118. wxzfbAmout = String.valueOf(map.get("amout"));
  119. }
  120. }
  121. predictIncome = CommonUtil.subtract(countIncome,predictIncome);
  122. String zsrAmout = CommonUtil.add(czAmout,wxzfbAmout);
  123. //返回数据
  124. res.set("countIncome", countIncome);
  125. res.set("predictIncome", predictIncome);
  126. res.set("czAmout", czAmout);
  127. res.set("zsrAmout", zsrAmout);
  128. res.set("time", time);
  129. return res;
  130. }
  131. /**
  132. * 总销售数量
  133. * @param session
  134. * @return
  135. * @throws Exception
  136. */
  137. @MINAction(value = SELECT_ALL_SALE)
  138. public MINActionResult selectAllSale (
  139. MINSession session) throws Exception {
  140. MINActionResult res = new MINActionResult();
  141. User user = session.getUser();
  142. //总实际金额
  143. String allSale = Service.lookup(IMINDataBaseService.class)
  144. .getMybatisMapper(OrderManageMapper.class).selectAllSale();
  145. //总商品成本
  146. String allCost = Service.lookup(IMINDataBaseService.class)
  147. .getMybatisMapper(OrderManageMapper.class).selectAllCost();
  148. BigDecimal num1 = new BigDecimal(allSale);
  149. BigDecimal num2 = new BigDecimal(allCost);
  150. BigDecimal allProfit = num1.subtract(num2);
  151. //返回数据
  152. res.set("allSale", allSale);
  153. res.set("allCost", allCost);
  154. res.set("allProfit", allProfit);
  155. return res;
  156. }
  157. /**
  158. * 销售数据
  159. * @param page
  160. * @param limit
  161. * @param session
  162. * @return
  163. * @throws Exception
  164. */
  165. @MINAction(value = SELECT_SALES_DATA)
  166. public MINActionResult selectSalesData (
  167. @MINParam(key = "page", defaultValue = "1") int page,
  168. @MINParam(key = "limit", defaultValue = "7") int limit,
  169. @MINParam(key = "proName") String proName,
  170. MINSession session) throws Exception {
  171. MINActionResult res = new MINActionResult();
  172. User user = session.getUser();
  173. Map<String, String> m = new HashMap<String, String>();
  174. m.put("proName", proName);
  175. MINRowBounds rows = new MINRowBounds(page, limit);
  176. List<Map<String, String>> detailList = Service.lookup(IMINDataBaseService.class)
  177. .getMybatisMapper(OrderManageMapper.class).selectProductInfo(rows, m);
  178. detailList = Service.lookup(IFormatService.class).formatCurrency(detailList, "amount", "proNums");
  179. //返回数据
  180. res.set(IMINBusinessConstant.F_PAGING_LAY, detailList);
  181. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount());
  182. return res;
  183. }
  184. /**
  185. * 总收入统计
  186. * @param session
  187. * @return
  188. * @throws Exception
  189. */
  190. // @MINAction(value = SELECT_ALL_INCOME)
  191. // public MINActionResult selectAllIncome (
  192. // MINSession session) throws Exception {
  193. // MINActionResult res = new MINActionResult();
  194. // User user = session.getUser();
  195. // //查询订单数
  196. // String orderNum = Service.lookup(IMINDataBaseService.class)
  197. // .getMybatisMapper(OrderManageMapper.class).selectCountOrderNum();
  198. // //查询累计收入
  199. // String countIncome = Service.lookup(IMINDataBaseService.class)
  200. // .getMybatisMapper(OrderManageMapper.class).selectCountIncome();
  201. // //查询总机台数
  202. // String countDevice = Service.lookup(IMINDataBaseService.class)
  203. // .getMybatisMapper(OrderManageMapper.class).selectCountDevice();
  204. // //返回数据
  205. // res.set("orderNum", orderNum);
  206. // res.set("countIncome", countIncome);
  207. // res.set("countDevice", countDevice);
  208. // return res;
  209. // }
  210. /**
  211. * 收入统计
  212. * @param page
  213. * @param limit
  214. * @param session
  215. * @return
  216. * @throws Exception
  217. */
  218. @MINAction(value = SELECT_INCOME_STATISTICS)
  219. public MINActionResult selectIncomeStatistics (
  220. @MINParam(key = "page", defaultValue = "1") int page,
  221. @MINParam(key = "limit", defaultValue = "10") int limit,
  222. @MINParam(key = "equNum") String equNum,
  223. @MINParam(key = "datesTime") String datesTime,
  224. MINSession session) throws Exception {
  225. MINActionResult res = new MINActionResult();
  226. User user = session.getUser();
  227. String branchId = user.getBranchId();
  228. MINRowBounds rows = new MINRowBounds(page, limit);
  229. //获取当前时间
  230. Date currentTime = new Date();
  231. String nowDate = DateUtil.format(currentTime,"yyyyMMdd");
  232. Map<String, String> m = new HashMap<String, String>();
  233. m.put("equNum", equNum);
  234. m.put("datesTime", datesTime);
  235. m.put("nowDate", nowDate);
  236. if(!"88888888".equals(branchId)) {
  237. m.put("branchId", branchId);
  238. }
  239. List<Map<String, String>> detailList = Service.lookup(IMINDataBaseService.class)
  240. .getMybatisMapper(OrderManageMapper.class).selectIncomeDetail(rows, m);
  241. detailList = Service.lookup(IFormatService.class).formatDate(detailList, "sellTime");
  242. detailList = Service.lookup(IFormatService.class).formatCurrency(detailList, "sellWxSum", "sellZfSum", "" +
  243. "sellMfSum", "allSell");
  244. //返回数据
  245. res.set(IMINBusinessConstant.F_PAGING_LAY, detailList);
  246. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount());
  247. return res;
  248. }
  249. /**
  250. * 取货记录
  251. * @param machineNo
  252. * @param orderNo
  253. * @param pickUpDates
  254. * @param page
  255. * @param limit
  256. * @param session
  257. * @return
  258. * @throws Exception
  259. */
  260. @MINAction(value = SELECT_PICKUP_RECORD)
  261. public MINActionResult selectPickupRecord (
  262. @MINParam(key = "machineNo") String machineNo,
  263. @MINParam(key = "orderNo") String orderNo,
  264. @MINParam(key = "pickUpDates") String pickUpDates,
  265. @MINParam(key = "equrelId") String equrelId,
  266. @MINParam(key = "vciId") String vciId,
  267. @MINParam(key = "pickupNo") String pickupNo,
  268. @MINParam(key = "page", defaultValue = "1") int page,
  269. @MINParam(key = "limit", defaultValue = "3") int limit,
  270. MINSession session) throws Exception {
  271. MINActionResult res = new MINActionResult();
  272. User user = session.getUser();
  273. String branchId = user.getBranchId();
  274. Map<String, String> m = new HashMap<String, String>();
  275. m.put("machineNo", machineNo);
  276. m.put("orderNo", orderNo);
  277. m.put("pickUpDates", pickUpDates);
  278. m.put("equrelId", equrelId);
  279. m.put("vciId", vciId);
  280. m.put("pickupNo", pickupNo);
  281. if(!"88888888".equals(branchId)) {
  282. m.put("branchId", branchId);
  283. }
  284. MINRowBounds rows = new MINRowBounds(page, limit);
  285. List<Map<String, String>> detailList = Service.lookup(IMINDataBaseService.class)
  286. .getMybatisMapper(OrderManageMapper.class).selectPickupRecord(m,rows);
  287. detailList = new MINCopyFormat("{stt:'sttDesc'}").format(detailList);
  288. detailList = Service.lookup(IFormatService.class).formatEnum(detailList,"{sttDesc:'PICKUP_STT'}");
  289. detailList = Service.lookup(IFormatService.class).formatDateTime(detailList, "pickUpTime");
  290. //返回数据
  291. res.set(IMINBusinessConstant.F_PAGING_LAY, detailList);
  292. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount());
  293. return res;
  294. }
  295. /**
  296. * 查询订单详情
  297. * @param machineNo
  298. * @param pickUpCode
  299. * @param creatdDtes
  300. * @param pickUpDates
  301. * @param pickUpState
  302. * @param page
  303. * @param limit
  304. * @param session
  305. * @return
  306. * @throws Exception
  307. */
  308. @MINAction(value = SELECT_ORDER_DETAIL)
  309. public MINActionResult selectOrderDetail (
  310. @MINParam(key = "machineNo") String machineNo,
  311. @MINParam(key = "pickUpCode") String pickUpCode,
  312. @MINParam(key = "equrelId") String equrelId,
  313. @MINParam(key = "creatdDtes") String creatdDtes,
  314. @MINParam(key = "pickUpDates") String pickUpDates,
  315. @MINParam(key = "pickUpState") String pickUpState,
  316. @MINParam(key = "page", defaultValue = "1") int page,
  317. @MINParam(key = "limit", defaultValue = "3") int limit,
  318. MINSession session) throws Exception {
  319. MINActionResult res = new MINActionResult();
  320. User user = session.getUser();
  321. String branchId = user.getBranchId();
  322. Map<String, String> m = new HashMap<String, String>();
  323. m.put("machineNo", machineNo);
  324. m.put("pickUpCode", pickUpCode);
  325. m.put("equrelId", equrelId);
  326. m.put("creatdDtes", creatdDtes);
  327. m.put("pickUpDates", pickUpDates);
  328. m.put("pickUpState", pickUpState);
  329. if(!"88888888".equals(branchId)) {
  330. m.put("branchId", branchId);
  331. }
  332. MINRowBounds rows = new MINRowBounds(page, limit);
  333. List<Map<String, String>> detailList = Service.lookup(IMINDataBaseService.class)
  334. .getMybatisMapper(OrderManageMapper.class).selectOrderDetail(m,rows);
  335. // 格式化数据
  336. detailList = Service.lookup(IFormatService.class).formatDateTime(detailList, "pickUpTime");
  337. detailList = Service.lookup(IFormatService.class).formatDateTime(detailList, "createTime");
  338. detailList = new MINCopyFormat("{stt:'sttDesc'}").format(detailList);
  339. detailList = Service.lookup(IFormatService.class).formatEnum(detailList,"{sttDesc:'ORDER_PICKUP_STT'}");
  340. //返回数据
  341. res.set(IMINBusinessConstant.F_PAGING_LAY, detailList);
  342. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows());
  343. return res;
  344. }
  345. /**
  346. *卡卷管理、取货、作废
  347. * @param orderNo
  348. * @param temp 操作0:作废,1:取货
  349. * @param session
  350. * @return
  351. * @throws Exception
  352. */
  353. @MINAction(value = UPDATE_ORDER_STT)
  354. public MINActionResult updateOrderStt(
  355. @MINParam ( key = "orderNo")String orderNo,
  356. @MINParam ( key = "temp")String temp,
  357. @MINParam ( key = "pickupNo")String pickupNo,
  358. @MINParam ( key = "detailsId")String detailsId,
  359. MINSession session) throws Exception{
  360. MINActionResult res = new MINActionResult();
  361. User user = session.getUser();
  362. VmDeliveryInf vd = Service.lookup(IMINDataBaseService.class)
  363. .getMybatisMapper(VmDeliveryInfMapper.class)
  364. .selectByPrimaryKey(pickupNo);
  365. if(vd == null || "2".equals(vd.getStatus()) || "6".equals(vd.getStatus())){
  366. throw new MINBusinessException("提货编号已提货");
  367. }
  368. String ordDetId = vd.getOrdDetId();
  369. VmOrderDetails vmOrderDetails = Service.lookup(IMINDataBaseService.class)
  370. .getMybatisMapper(VmOrderDetailsMapper.class)
  371. .selectByPrimaryKey(ordDetId);
  372. if(vmOrderDetails == null||"01".equals(vmOrderDetails.getIsDelivery())){
  373. throw new MINBusinessException("提货编号已提货");
  374. }
  375. String info = "";
  376. if ("0".equals(temp)) {
  377. vd.setStatus("6");
  378. info = "废止";
  379. //修改提货表
  380. Service.lookup(IMINDataBaseService.class)
  381. .getMybatisMapper(VmDeliveryInfMapper.class)
  382. .updateByPrimaryKeySelective(vd);
  383. //修改订单详情表
  384. vmOrderDetails.setIsDelivery("01");
  385. vmOrderDetails.setPickupTime(DateUtil.getCurrentDateTimeString());
  386. Service.lookup(IMINDataBaseService.class)
  387. .getMybatisMapper(VmOrderDetailsMapper.class)
  388. .updateByPrimaryKeySelective(vmOrderDetails);
  389. }else if("1".equals(temp)) {
  390. String url = Service.lookup(IPropertiesService.class)
  391. .getSystemProperties().get("V01_SHOUHUO_NOTIFY_URL").getKey();
  392. StringBuffer paramStr = new StringBuffer();
  393. paramStr.append("MINView=JSON&");
  394. paramStr.append("deliveryNo=");
  395. paramStr.append(pickupNo);
  396. url = url.concat("/DeliveryAction/makeDeliveryForMachineNoSession?");
  397. String jsonObj = HttpPostUtil.sendPost(url, paramStr.toString());
  398. if(CommonUtil.isEmpty(jsonObj)){
  399. throw new MINBusinessException("操作失败!请重新操作");
  400. }
  401. JSONObject js2 = JSONObject.fromObject(jsonObj);
  402. String mINStatus = js2.getString("MINStatus");
  403. String mINErrorMessage = js2.getString("MINErrorMessage");
  404. //{"msg":"没有提货信息!","code":1,"MINPage":{"charset":"UTF-8","cache":false,"view":"JSON","page":"","type":"","contentType":"text/html"},"MINLangLocale":"zh_CN","MINStatus":1,"MINTime":"2020-12-13 01:41:56","MINErrorMessage":"没有提货信息!"}
  405. if(!"0".equals(mINStatus)){
  406. throw new MINBusinessException(mINErrorMessage);
  407. }
  408. //发送请求
  409. info = "发货";
  410. }
  411. //日志
  412. String logInfo = user.getName()+"-更新提货单状态:" +info+ ",订单号"+pickupNo;
  413. Service.lookup(ILogService.class).logging(session, logInfo);
  414. return res;
  415. }
  416. }