MachineManageAction.java 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498
  1. package com.minpay.mt.machine.action;
  2. import com.itextpdf.text.pdf.qrcode.WriterException;
  3. import com.min.util.CommonUtil;
  4. import com.minpay.common.bean.User;
  5. import com.minpay.common.constant.Constant;
  6. import com.minpay.common.format.IFormatService;
  7. import com.minpay.common.service.IPropertiesService;
  8. import com.minpay.common.service.IPublicService;
  9. import com.minpay.common.util.DateUtil;
  10. import com.minpay.common.util.UpLoadFile;
  11. import com.minpay.db.table.mapper.VmEquipmentInfMapper;
  12. import com.minpay.db.table.mapper.VmProEquRelMapper;
  13. import com.minpay.db.table.model.VmEquipmentInf;
  14. import com.minpay.db.table.model.VmEquipmentInfExample;
  15. import com.minpay.db.table.model.VmProEquRel;
  16. import com.minpay.db.table.model.VmProEquRelExample;
  17. import com.minpay.db.table.own.mapper.MachineManageMapper;
  18. import com.minpay.huicai.util.EquCodeCreateUtil;
  19. import com.startup.minpay.frame.business.IMINAction;
  20. import com.startup.minpay.frame.business.res.MINActionResult;
  21. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  22. import com.startup.minpay.frame.constant.IMINTransactionEnum;
  23. import com.startup.minpay.frame.data.format.MINCopyFormat;
  24. import com.startup.minpay.frame.exception.MINBusinessException;
  25. import com.startup.minpay.frame.jdbc.MINRowBounds;
  26. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  27. import com.startup.minpay.frame.service.base.Service;
  28. import com.startup.minpay.frame.session.MINSession;
  29. import com.startup.minpay.frame.target.MINAction;
  30. import com.startup.minpay.frame.target.MINComponent;
  31. import com.startup.minpay.frame.target.MINParam;
  32. import java.io.*;
  33. import java.util.HashMap;
  34. import java.util.List;
  35. import java.util.Map;
  36. import java.util.stream.Collectors;
  37. /**
  38. * 设备管理
  39. * @author pangjl
  40. * 20190325
  41. */
  42. @MINComponent
  43. public class MachineManageAction implements IMINAction {
  44. /**
  45. * 查看设备
  46. */
  47. public final static String QUERY_EQUMENT_INF = "queryEqumentInf";
  48. /**
  49. * 添加设备
  50. */
  51. public final static String ADD_PRODUCT_INF = "addMachine";
  52. /**
  53. * 修改设备
  54. */
  55. public final static String MODIFY_PRODUCT_INF = "modifyProductInf";
  56. /**
  57. * 更改设备状态
  58. */
  59. public final static String MODIFY_PRODUCT_STATE = "modifyProductState";
  60. /**
  61. * 查询设备中商品
  62. */
  63. public final static String QUERY_PROEQUREL = "queryProEquRel";
  64. /**
  65. * 查看正常状态商品
  66. */
  67. public final static String QUERY_PRODUCTZ = "queryProductz";
  68. /**
  69. * 设备添加商品
  70. */
  71. public final static String ADD_PROEQUREL = "addProEquRel";
  72. /**
  73. * 修改设备商品
  74. */
  75. public final static String EDIT_PROEQUREL = "editProEquRel";
  76. /**
  77. * 查询编辑设备中商品
  78. */
  79. public final static String QUERY_PROEQU = "queryProEqu";
  80. /**
  81. * 删除货道
  82. */
  83. public final static String DEL_EQUPRO = "delEquPro";
  84. /**
  85. * 删除设备中商品
  86. */
  87. public final static String DEL_PROEQU = "delProEqu";
  88. /**
  89. * 查询设备列表
  90. */
  91. public final static String QUERY_EQUIPMENT_LINE = "queryEquipmentLine";
  92. /**
  93. * 多选设备复制商品
  94. */
  95. public final static String ADD_PROEQURELALL_COPY = "addProEquRelAllCopy";
  96. /**
  97. * 关闭音乐
  98. */
  99. public final static String CLOSE_SONG = "closeSong";
  100. /**一键补货*/
  101. public final static String ADD_PROEQUREL_NUM = "addProEquRelNum";
  102. /**一键设置商品价格*/
  103. public final static String EDIT_PROEQUREL_PRICE = "editProEquRelPrice";
  104. /** 生成包含字符串信息的二维码图片**/
  105. public static final String CREATE_QRCODE = "createQrCode";
  106. /**补货*/
  107. public final static String EDIT_PROEQUREL_NUM = "editProEquRelNum";
  108. /**解绑机台号*/
  109. public final static String DELETE_EQU = "deleteEqu";
  110. /**生成指定机器指定行列的货道*/
  111. public final static String ADD_PRO_EQU_REL = "addProEquRelLineRow";
  112. private boolean contains;
  113. /**
  114. * 查看设备
  115. *
  116. * @param createUser 添加人
  117. * @param page
  118. * @param limit
  119. * @return
  120. * @throws Exception
  121. */
  122. @MINAction(value = QUERY_EQUMENT_INF)
  123. public MINActionResult queryEqumentInf(
  124. @MINParam(key = "machineId") String machineId,
  125. @MINParam(key = "state") String state,
  126. @MINParam(key = "machineName") String machineName,
  127. @MINParam(key = "mchntId") String mchntId,
  128. @MINParam(key = "equType") String equType,
  129. @MINParam(key = "createUser") String createUser,
  130. @MINParam(key = "page", defaultValue = "1") int page,
  131. @MINParam(key = "limit", defaultValue = "3") int limit,
  132. MINSession session) throws Exception {
  133. MINActionResult res = new MINActionResult();
  134. User user = session.getUser();
  135. String passwardKey = Service.lookup(IPropertiesService.class)
  136. .getSystemProperties().get("WALLET_TO_METTING_PASSWORD_KEY").getKey();
  137. Map<String, String> map = new HashMap<String, String>();
  138. map.put("id", machineId);
  139. if(Constant.DEFAULT_INSTITUTIONS.equals( user.getBranchId())){
  140. map.put("mchntId", mchntId);
  141. }else{
  142. map.put("mchntId", user.getBranchId());
  143. }
  144. map.put("equType", equType);
  145. map.put("machineName", machineName);
  146. map.put("createUser", createUser);
  147. map.put("state", state);
  148. map.put("channel", user.getChannel());//渠道号
  149. //验证操作员权限
  150. MINRowBounds rows = new MINRowBounds(page, limit);
  151. //执行查询
  152. List<Map<String, String>> list = Service.lookup(IMINDataBaseService.class)
  153. .getMybatisMapper(MachineManageMapper.class)
  154. .machineInf(map, rows);
  155. //在线数
  156. int online = list.stream().filter(item -> item.get("state").equals("00")).collect(Collectors.toList()).size();
  157. int unOnline = list.stream().filter(item -> item.get("state").equals("01")).collect(Collectors.toList()).size();
  158. //格式化时间和状态
  159. list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime");
  160. list = new MINCopyFormat("{state:'stateDesc',equType :'equTypeDesc'}").format(list);
  161. list = Service.lookup(IFormatService.class).formatEnum(list, "{stateDesc:'EQUIPMENT_STATE',equTypeDesc:'EQUIPMENT_TYPE'}");
  162. //返回数据
  163. res.set(IMINBusinessConstant.F_PAGING_LAY, list);
  164. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows());
  165. res.set("online",String.valueOf(online));
  166. res.set("unOnline",String.valueOf(unOnline));
  167. return res;
  168. }
  169. /**
  170. * 添加设备
  171. *
  172. * @param session
  173. * @return
  174. * @throws MINBusinessException
  175. */
  176. @MINAction(value = ADD_PRODUCT_INF, transaction = IMINTransactionEnum.CMT)
  177. public MINActionResult addMachine(
  178. @MINParam(key = "equCode") String equCode,
  179. @MINParam(key = "account") String account,
  180. @MINParam(key = "temLine") String temLine,
  181. @MINParam(key = "temRow") String temRow,
  182. MINSession session) throws MINBusinessException, IOException {
  183. MINActionResult res = new MINActionResult();
  184. //获取当前时间
  185. String nowTime = DateUtil.getCurrentDateTimeString();
  186. // 获取操作员信息
  187. User user = session.getUser();
  188. if (CommonUtil.isEmpty(equCode)) {
  189. throw new MINBusinessException("起始机台号为空");
  190. }
  191. if (CommonUtil.isEmpty(account)) {
  192. throw new MINBusinessException("生成数量为空");
  193. }
  194. if (CommonUtil.isEmpty(temLine)) {
  195. throw new MINBusinessException("生成货道行数量为空");
  196. }
  197. if (CommonUtil.isEmpty(temRow)) {
  198. throw new MINBusinessException("生成货道列数量为空");
  199. }
  200. int size = Integer.parseInt(account);
  201. VmEquipmentInfExample example = new VmEquipmentInfExample();
  202. example.createCriteria().andMachineNoEqualTo(equCode).andStateEqualTo("00");
  203. List<VmEquipmentInf> vmEquipmentInfList = Service.lookup(IMINDataBaseService.class)
  204. .getMybatisMapper(VmEquipmentInfMapper.class)
  205. .selectByExample(example);
  206. if (vmEquipmentInfList.size() > 0) {
  207. throw new MINBusinessException(equCode + "机台号已存在");
  208. }
  209. for (int j = 1; j < size; j++) {
  210. VmEquipmentInfExample examples = new VmEquipmentInfExample();
  211. examples.createCriteria().andMachineNoEqualTo(CommonUtil.add(equCode, String.valueOf(j))).andStateEqualTo("00");
  212. List<VmEquipmentInf> vmEquipmentInfLists = Service.lookup(IMINDataBaseService.class)
  213. .getMybatisMapper(VmEquipmentInfMapper.class)
  214. .selectByExample(examples);
  215. if (vmEquipmentInfLists.size() > 0) {
  216. throw new MINBusinessException(equCode + "机台号已存在");
  217. }
  218. }
  219. //获取当前用户信息
  220. User u = session.getUser();
  221. //获取用户id
  222. String userId = u.getBranchId();
  223. //开发环境修改配置
  224. String basePath = "/home/images/"+ userId+".jpg"; //与nginx配置相同
  225. String os = System.getProperty("os.name");
  226. if(os.toLowerCase().startsWith("win")){
  227. System.out.println(os + " can't gunzip");
  228. basePath = "D:/images/"+ userId+".jpg"; //与nginx配置相同
  229. }
  230. String id = Service.lookup(IPublicService.class).getSequence("EQU_MACHINE_NO");
  231. File file = new File(basePath);
  232. //获取父目录
  233. File fileParent = file.getParentFile();
  234. //判断是否存在
  235. if (!fileParent.exists()) {
  236. fileParent.mkdirs();
  237. }
  238. //获取渠道号
  239. String channel = "V01";
  240. // 加密客户号
  241. OutputStream outputStream = new FileOutputStream(file);
  242. String serviceUrl = Service.lookup(IPropertiesService.class)
  243. .getSystemProperties().get(channel+"_TO_MACHINE_ERWERMA").getKey();
  244. serviceUrl = "http://".concat(serviceUrl.concat("/admin/h5/index.html?equId=").concat(id));
  245. //String urlString = URLEncoder.encode(, "GBK");
  246. // 生成二维码图片到本地
  247. try {
  248. EquCodeCreateUtil.createQrCode(outputStream,serviceUrl,900,"JPEG");
  249. } catch (com.google.zxing.WriterException e) {
  250. // TODO Auto-generated catch block
  251. e.printStackTrace();
  252. }
  253. outputStream.close();
  254. // 上传图片到服务器
  255. InputStream inputSteam = new FileInputStream(file);
  256. String url = UpLoadFile.uploadImg(inputSteam,"jpg",channel,"00");
  257. inputSteam.close();
  258. // 删除本地图片
  259. file.delete();
  260. VmEquipmentInf pro = new VmEquipmentInf();
  261. pro.setId(id);
  262. pro.setMachineNo(equCode);
  263. pro.setImeiAddr(equCode);
  264. pro.setChannel("V01");
  265. pro.setState("01");
  266. pro.setCreateUser(user.getId());
  267. pro.setCreateTime(nowTime);
  268. pro.setRows(temRow);
  269. pro.setLines(temLine);
  270. pro.setUrlCode(url);
  271. pro.setEquType("00"); //默认支付盒子售货机
  272. pro.setBranchid(user.getBranchid());
  273. Service.lookup(IMINDataBaseService.class)
  274. .getMybatisMapper(VmEquipmentInfMapper.class)
  275. .insertSelective(pro);
  276. for (int i = 1; i < size; i++) {
  277. String ids = Service.lookup(IPublicService.class).getSequence("EQU_MACHINE_NO");
  278. serviceUrl = "http://".concat(serviceUrl.concat("/admin/h5/index.html?equId=").concat(ids));
  279. //String urlString = URLEncoder.encode(, "GBK");
  280. OutputStream outputStreams = new FileOutputStream(file);
  281. // 生成二维码图片到本地
  282. try {
  283. EquCodeCreateUtil.createQrCode(outputStreams,serviceUrl,900,"JPEG");
  284. } catch (com.google.zxing.WriterException e) {
  285. // TODO Auto-generated catch block
  286. e.printStackTrace();
  287. }
  288. outputStreams.close();
  289. // 上传图片到服务器
  290. InputStream inputSteams = new FileInputStream(file);
  291. url = UpLoadFile.uploadImg(inputSteams,"jpg",channel,"00");
  292. inputSteams.close();
  293. // 删除本地图片
  294. file.delete();
  295. VmEquipmentInf pros = new VmEquipmentInf();
  296. pros.setId(ids);
  297. pros.setChannel("V01");
  298. pros.setMachineNo(CommonUtil.add(equCode, String.valueOf(i)));
  299. pros.setImeiAddr(CommonUtil.add(equCode, String.valueOf(i)));
  300. pros.setState("01");
  301. pros.setCreateUser(user.getId());
  302. pros.setCreateTime(nowTime);
  303. pros.setRows(temRow);
  304. pros.setLines(temLine);
  305. pros.setUrlCode(url);
  306. pros.setBranchid(user.getBranchid());
  307. Service.lookup(IMINDataBaseService.class)
  308. .getMybatisMapper(VmEquipmentInfMapper.class)
  309. .insertSelective(pros);
  310. }
  311. /*// 记录操作日志
  312. String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id;
  313. Service.lookup(ILogService.class).logging(session, logInfo);*/
  314. return res;
  315. }
  316. /**
  317. * 查询设备中商品
  318. *
  319. * @param session
  320. * @return
  321. * @throws MINBusinessException
  322. */
  323. @MINAction(value = QUERY_PROEQUREL)
  324. public MINActionResult queryProEquRel(
  325. @MINParam(key = "equId") String equId,
  326. MINSession session
  327. ) throws MINBusinessException {
  328. MINActionResult res = new MINActionResult();
  329. User user = session.getUser();
  330. //渠道
  331. String channel = user.getChannel();
  332. // 查询条件
  333. Map<String, String> map = new HashMap<String, String>();
  334. map.put("channel", "V01");
  335. map.put("equId", equId);
  336. List<Map<String, Object>> list = Service.lookup(IMINDataBaseService.class)
  337. .getMybatisMapper(MachineManageMapper.class)
  338. .queryProEquRel(map);
  339. //格式化时间和状态
  340. list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime");
  341. list = new MINCopyFormat("{perState:'sttDesc',isPromotton:'isPromottonDesc',isFragile:'isFragileDesc'}").format(list);
  342. list = Service.lookup(IFormatService.class).formatEnum(list, "{sttDesc:'PROEQUREL_STATE',isPromottonDesc:'IS_PROMOTION',isFragileDesc:'IS_FRAGILE'}");
  343. //传递数据
  344. res.set(IMINBusinessConstant.F_PAGING_LAY, list);
  345. return res;
  346. }
  347. /**
  348. * 查看商品
  349. *
  350. * @param name 商品名称
  351. * @param brandName 品牌名称
  352. * @param model 商品型号
  353. * @param createUser 添加人
  354. * @param dates 添加时间
  355. * @param page
  356. * @param limit
  357. * @return
  358. * @throws MINBusinessException
  359. */
  360. @MINAction(value = QUERY_PRODUCTZ)
  361. public MINActionResult queryProductz(
  362. @MINParam(key = "name") String name,
  363. @MINParam(key = "model") String model,
  364. @MINParam(key = "dates") String dates,
  365. @MINParam(key = "state") String state,
  366. @MINParam(key = "brandName") String brandName,
  367. @MINParam(key = "categoryId") String categoryId,
  368. @MINParam(key = "createUser") String createUser,
  369. @MINParam(key = "page", defaultValue = "1") int page,
  370. @MINParam(key = "limit", defaultValue = "3") int limit,
  371. MINSession session) throws MINBusinessException {
  372. MINActionResult res = new MINActionResult();
  373. User user = session.getUser();
  374. Map<String, String> map = new HashMap<String, String>();
  375. //按商品名称,商品品牌进行模糊查询
  376. map.put("name", name); //商品名称
  377. map.put("state", state);//状态
  378. map.put("model", model);
  379. map.put("dates", dates);
  380. map.put("brandName", brandName);
  381. map.put("createUser", createUser);
  382. map.put("channel", "V01");//渠道号
  383. map.put("category", categoryId);//分类
  384. //验证操作员权限
  385. if ("00".equals(user.getIdentity())) {
  386. map.put("userId", user.getId());
  387. }
  388. /* if("10000002".equals(user.getRoleId())){
  389. map.put("userId",user.getId());
  390. }*/
  391. //分页
  392. MINRowBounds rows = new MINRowBounds(page, limit);
  393. //执行查询
  394. List<Map<String, String>> list = Service.lookup(IMINDataBaseService.class)
  395. .getMybatisMapper(MachineManageMapper.class)
  396. .queryProductz(map, rows);
  397. //格式化时间和状态
  398. list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime");
  399. list = new MINCopyFormat("{history:'historyDesc',state:'stateDesc',source:'sourceDesc'}").format(list);
  400. list = Service.lookup(IFormatService.class).formatEnum(list, "{historyDesc:'PRODUCT_HISTORY',stateDesc:'PRODUCT_STATE',sourceDesc:'PRODUCT_SOURCE'}");
  401. //返回数据
  402. res.set(IMINBusinessConstant.F_PAGING_LAY, list);
  403. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows());
  404. return res;
  405. }
  406. /**
  407. * 设备添加商品
  408. *
  409. * @param perRow 货道层
  410. * @param perLine 货道列
  411. * @param perNum 货道容量
  412. * @param numbers 商品余量
  413. * @param sallPrice 售货价
  414. * @param gamePrice 游戏价
  415. * @param costPrice 成本价
  416. * @param isPromotton 是否促销
  417. * @param promottonPrice 促销价
  418. * @param isFragile 是否易碎
  419. * @param perRemarks 备注
  420. * @param proId 商品id
  421. * @param equId 设备id
  422. * @param session
  423. * @return
  424. * @throws MINBusinessException
  425. */
  426. @MINAction(value = ADD_PROEQUREL)
  427. public MINActionResult addProEquRel(
  428. @MINParam(key = "aisle") String aisle,
  429. @MINParam(key = "perRow") String perRow,
  430. @MINParam(key = "perLine") String perLine,
  431. @MINParam(key = "perNum") String perNum,
  432. @MINParam(key = "numbers") String numbers,
  433. @MINParam(key = "sallPrice") String sallPrice,
  434. @MINParam(key = "gamePrice") String gamePrice,
  435. @MINParam(key = "costPrice") String costPrice,
  436. @MINParam(key = "isPromotton") String isPromotton,
  437. @MINParam(key = "promottonPrice") String promottonPrice,
  438. @MINParam(key = "type") String type,
  439. @MINParam(key = "isFragile") String isFragile,
  440. @MINParam(key = "perRemarks") String perRemarks,
  441. @MINParam(key = "proId") String proId,
  442. @MINParam(key = "equId") String equId,
  443. @MINParam(key = "luck") String luck,
  444. MINSession session
  445. ) throws MINBusinessException {
  446. MINActionResult res = new MINActionResult();
  447. //当前时间
  448. String dateTime = DateUtil.getCurrentDateTimeString();
  449. User user = session.getUser();
  450. //操作员id
  451. String uId = user.getId();
  452. //渠道
  453. String channel = user.getChannel();
  454. //校验设备是否正常
  455. VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class)
  456. .getMybatisMapper(VmEquipmentInfMapper.class)
  457. .selectByPrimaryKey(equId);
  458. if (equipmentInf == null) {
  459. throw new MINBusinessException("该设备不存在!");
  460. } else if (equipmentInf.getState().equals("03")) {
  461. throw new MINBusinessException("该设备已销毁!");
  462. }
  463. int comcosAndsal = CommonUtil.compare(costPrice, sallPrice);
  464. /* int comcosAndgam = CommonUtil.compare(costPrice, gamePrice);
  465. int comgamAndsal = CommonUtil.compare(gamePrice, sallPrice);*/
  466. /* int comcosAndpro = CommonUtil.compare(costPrice, promottonPrice);*/
  467. int comproAndsal = CommonUtil.compare(promottonPrice, sallPrice);
  468. int comnumAndper = CommonUtil.compare(numbers, perNum);
  469. if (comcosAndsal == 1 || comcosAndsal == 0) {
  470. throw new MINBusinessException("成本价不能大于或等于售货价!");
  471. }
  472. /* if (comcosAndgam == 1 || comcosAndgam == 0) {
  473. throw new MINBusinessException("成本价不能大于或等于游戏价!");
  474. }
  475. if (comgamAndsal == 1 || comgamAndsal == 0) {
  476. throw new MINBusinessException("游戏价不能大于或等于售货价!");
  477. }*/
  478. /*if (comcosAndpro == 1 || comcosAndpro == 0) {
  479. throw new MINBusinessException("成本价不能大于或等于促销价!");
  480. }*/
  481. if (comproAndsal == 1 || comproAndsal == 0) {
  482. throw new MINBusinessException("促销价不能大于或等于售货价!");
  483. }
  484. if (comnumAndper == 1) {
  485. throw new MINBusinessException("商品余量不能大于货道容量!");
  486. }
  487. //校验商品是否正常
  488. // VmProductInf pro = Service.lookup(IMINDataBaseService.class)
  489. // .getMybatisMapper(VmProductInfMapper.class)
  490. // .selectByPrimaryKey(proId);
  491. // if(pro == null||pro.getState().equals("2")) {
  492. // throw new BusinessCodeException("JINM0123");//商品信息异常
  493. // }
  494. //设备新增商品
  495. String id = Service.lookup(IPublicService.class).getSequence("VM_PROEQUREL_ID");
  496. VmProEquRel proEquRel = new VmProEquRel();
  497. proEquRel.setId(id); //设备商品关联表id
  498. proEquRel.setProductId(proId); //商品id
  499. proEquRel.setEquipmentId(equId); //设备id
  500. VmProEquRelExample example = new VmProEquRelExample();
  501. if (CommonUtil.isEmpty(aisle)) {
  502. example.createCriteria().andChannelEqualTo(channel)
  503. .andEquipmentIdEqualTo(equId)
  504. .andAisleEqualTo(perRow.concat(perLine))
  505. .andExeitStateEqualTo("00");
  506. List<VmProEquRel> list = Service.lookup(IMINDataBaseService.class)
  507. .getMybatisMapper(VmProEquRelMapper.class)
  508. .selectByExample(example);
  509. if (list.size() != 0) {
  510. throw new MINBusinessException("该设备默认货道指令已被使用!");
  511. }
  512. proEquRel.setAisle(perRow.concat(perLine)); //货道指令
  513. } else {
  514. example.createCriteria().andChannelEqualTo(channel)
  515. .andEquipmentIdEqualTo(equId)
  516. .andAisleEqualTo(aisle)
  517. .andExeitStateEqualTo("00");
  518. List<VmProEquRel> list = Service.lookup(IMINDataBaseService.class)
  519. .getMybatisMapper(VmProEquRelMapper.class)
  520. .selectByExample(example);
  521. if (list.size() != 0) {
  522. throw new MINBusinessException("该设备货道指令已使用!");
  523. }
  524. proEquRel.setAisle(aisle); //货道指令
  525. }
  526. proEquRel.setCargoWayRow(perRow); //货道层
  527. proEquRel.setCargoWayLine(perLine); //货道列
  528. proEquRel.setCargoWayNums(perNum); //货道容量
  529. proEquRel.setProductNums(numbers); //商品余量
  530. proEquRel.setSallPrice(sallPrice); //售货价
  531. proEquRel.setGamePrice(gamePrice); //游戏价
  532. proEquRel.setCostPrice(costPrice); //成本价
  533. proEquRel.setIsPromotion(isPromotton); //是否促销
  534. proEquRel.setPromotionPrice(promottonPrice); //促销价
  535. /* proEquRel.setIsFragile(isFragile); //是否易碎
  536. */
  537. proEquRel.setUserId(uId); //商户id
  538. proEquRel.setRemarks(perRemarks); //备注
  539. proEquRel.setGameType(type); //游戏类型
  540. proEquRel.setChannel(channel); //渠道
  541. proEquRel.setCreateUser(uId); //创建人
  542. proEquRel.setCreateTime(dateTime); //创建时间
  543. proEquRel.setModifyUser(uId); //最后修改人
  544. proEquRel.setModifyTime(dateTime); //最后修改时间
  545. proEquRel.setExeitState("00"); //状态 00正常
  546. Service.lookup(IMINDataBaseService.class)
  547. .getMybatisMapper(VmProEquRelMapper.class)
  548. .insertSelective(proEquRel);
  549. return res;
  550. }
  551. /**
  552. * 修改设备商品
  553. *
  554. * @param perId 设备商品关联id
  555. * @param perRow 货道层
  556. * @param perLine 货道列
  557. * @param perNum 货道容量
  558. * @param numbers 商品余量
  559. * @param sallPrice 售货价
  560. * @param gamePrice 游戏价
  561. * @param costPrice 成本价
  562. * @param isPromotton 是否促销
  563. * @param promottonPrice 促销价
  564. * @param isFragile 是否易碎
  565. * @param perRemarks 备注
  566. * @param proId 商品id
  567. * @param equId 设备id
  568. * @param perState 状态
  569. * @param session
  570. * @return
  571. * @throws MINBusinessException
  572. */
  573. @MINAction(value = EDIT_PROEQUREL)
  574. public MINActionResult editProEquRel(
  575. @MINParam(key = "perId") String perId,
  576. @MINParam(key = "aisle") String aisle,
  577. @MINParam(key = "perRow") String perRow,
  578. @MINParam(key = "perLine") String perLine,
  579. @MINParam(key = "perNum") String perNum,
  580. @MINParam(key = "numbers") String numbers,
  581. @MINParam(key = "sallPrice") String sallPrice,
  582. @MINParam(key = "gamePrice") String gamePrice,
  583. @MINParam(key = "costPrice") String costPrice,
  584. @MINParam(key = "type") String type,
  585. @MINParam(key = "isPromotton") String isPromotton,
  586. @MINParam(key = "promottonPrice") String promottonPrice,
  587. @MINParam(key = "isFragile") String isFragile,
  588. @MINParam(key = "perRemarks") String perRemarks,
  589. @MINParam(key = "proId") String proId,
  590. @MINParam(key = "equId") String equId,
  591. @MINParam(key = "perState") String perState,
  592. @MINParam(key = "luck") String luck,
  593. MINSession session
  594. ) throws MINBusinessException {
  595. MINActionResult res = new MINActionResult();
  596. //当前时间
  597. String dateTime = DateUtil.getCurrentDateTimeString();
  598. User user = session.getUser();
  599. //操作员id
  600. String uId = user.getId();
  601. //渠道
  602. String channel = user.getChannel();
  603. //校验设备是否正常
  604. VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class)
  605. .getMybatisMapper(VmEquipmentInfMapper.class)
  606. .selectByPrimaryKey(equId);
  607. if (equipmentInf == null) {
  608. throw new MINBusinessException("该设备不存在!");
  609. } else if (equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)) {
  610. throw new MINBusinessException("该设备已销毁!");
  611. }
  612. int comcosAndsal = CommonUtil.compare(costPrice, sallPrice);
  613. /* int comcosAndgam = CommonUtil.compare(costPrice, gamePrice);
  614. int comgamAndsal = CommonUtil.compare(gamePrice, sallPrice);*/
  615. // int comcosAndpro = CommonUtil.compare(costPrice, promottonPrice);
  616. int comproAndsal = CommonUtil.compare(promottonPrice, sallPrice);
  617. int comnumAndper = CommonUtil.compare(numbers, perNum);
  618. if (comcosAndsal == 1 || comcosAndsal == 0) {
  619. throw new MINBusinessException("成本价不能大于或等于售货价!");
  620. }
  621. /*if (comcosAndgam == 1 || comcosAndgam == 0) {
  622. throw new MINBusinessException("成本价不能大于或等于游戏价!");
  623. }
  624. if (comgamAndsal == 1 || comgamAndsal == 0) {
  625. throw new MINBusinessException("游戏价不能大于或等于售货价!");
  626. }*/
  627. // if (comcosAndpro == 1 || comcosAndpro == 0) {
  628. // throw new MINBusinessException("成本价不能大于或等于促销价!");
  629. // }
  630. if (comproAndsal == 1 || comproAndsal == 0) {
  631. throw new MINBusinessException("促销价不能大于或等于售货价!");
  632. }
  633. if (comnumAndper == 1) {
  634. throw new MINBusinessException("商品余量不能大于货道容量!");
  635. }
  636. //校验商品是否正常
  637. // VmProductInf pro = Service.lookup(IMINDataBaseService.class)
  638. // .getMybatisMapper(VmProductInfMapper.class)
  639. // .selectByPrimaryKey(proId);
  640. VmProEquRel proEquRel = Service.lookup(IMINDataBaseService.class)
  641. .getMybatisMapper(VmProEquRelMapper.class)
  642. .selectByPrimaryKey(perId);
  643. // if(pro == null||pro.getState().equals("2")||proEquRel == null||proEquRel.getExeitState().equals("2")) {
  644. // throw new BusinessCodeException("JINM0123");//商品信息异常
  645. // }
  646. //修改设备新增商品
  647. if (!CommonUtil.isEmpty(proId)) {
  648. proEquRel.setProductId(proId); //商品id
  649. }
  650. if (!CommonUtil.isEmpty(equId)) {
  651. proEquRel.setEquipmentId(equId); //设备id
  652. }
  653. if (!CommonUtil.isEmpty(aisle)) {
  654. VmProEquRelExample example = new VmProEquRelExample();
  655. example.createCriteria().andChannelEqualTo(channel)
  656. .andEquipmentIdEqualTo(equId)
  657. .andAisleEqualTo(aisle)
  658. .andExeitStateEqualTo(Constant.PROEQUREL_STT_00)
  659. .andIdNotEqualTo(perId);
  660. List<VmProEquRel> list = Service.lookup(IMINDataBaseService.class)
  661. .getMybatisMapper(VmProEquRelMapper.class)
  662. .selectByExample(example);
  663. if (list.size() != 0) {
  664. throw new MINBusinessException("该设备货道指令已使用!");
  665. }
  666. proEquRel.setAisle(aisle); //货道指令
  667. }
  668. if (!CommonUtil.isEmpty(perRow)) {
  669. proEquRel.setCargoWayRow(perRow); //货道层
  670. }
  671. if (!CommonUtil.isEmpty(perLine)) {
  672. proEquRel.setCargoWayLine(perLine); //货道列
  673. }
  674. if (!CommonUtil.isEmpty(perNum)) {
  675. proEquRel.setCargoWayNums(perNum); //货道容量
  676. }
  677. if (!CommonUtil.isEmpty(numbers)) {
  678. proEquRel.setProductNums(numbers); //商品余量
  679. }
  680. if (!CommonUtil.isEmpty(sallPrice)) {
  681. proEquRel.setSallPrice(sallPrice); //售货价
  682. }
  683. if (!CommonUtil.isEmpty(gamePrice)) {
  684. proEquRel.setGamePrice(gamePrice); //游戏价
  685. }
  686. if (!CommonUtil.isEmpty(costPrice)) {
  687. proEquRel.setCostPrice(costPrice); //成本价
  688. }
  689. if (!CommonUtil.isEmpty(isPromotton)) {
  690. proEquRel.setIsPromotion(isPromotton); //是否促销
  691. }
  692. if (!CommonUtil.isEmpty(promottonPrice)) {
  693. proEquRel.setPromotionPrice(promottonPrice); //促销价
  694. }
  695. /*if(!CommonUtil.isEmpty(isFragile)){
  696. proEquRel.setIsFragile(isFragile); //是否易碎
  697. }*/
  698. if (!CommonUtil.isEmpty(perRemarks)) {
  699. proEquRel.setRemarks(perRemarks); //备注
  700. }
  701. proEquRel.setGameType(type); //游戏类型
  702. proEquRel.setModifyUser(uId); //最后修改人
  703. proEquRel.setModifyTime(dateTime); //最后修改时间
  704. if (!CommonUtil.isEmpty(perState)) {
  705. proEquRel.setExeitState(perState); //状态
  706. }
  707. Service.lookup(IMINDataBaseService.class)
  708. .getMybatisMapper(VmProEquRelMapper.class)
  709. .updateByPrimaryKeySelective(proEquRel);
  710. return res;
  711. }
  712. /**
  713. * 查询设备中商品
  714. *
  715. * @param session
  716. * @return
  717. * @throws MINBusinessException
  718. */
  719. @MINAction(value = QUERY_PROEQU)
  720. public MINActionResult queryProEqu(
  721. @MINParam(key = "equId") String equId,
  722. @MINParam(key = "perId") String perId,
  723. MINSession session
  724. ) throws MINBusinessException {
  725. MINActionResult res = new MINActionResult();
  726. User user = session.getUser();
  727. //渠道
  728. String channel = user.getChannel();
  729. // 查询条件
  730. Map<String, String> map = new HashMap<String, String>();
  731. map.put("channel", "V01");
  732. map.put("equId", equId);
  733. map.put("perId", perId);
  734. List<Map<String, Object>> list = Service.lookup(IMINDataBaseService.class)
  735. .getMybatisMapper(MachineManageMapper.class)
  736. .queryProEquRel(map);
  737. //格式化时间和状态
  738. list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime");
  739. list = new MINCopyFormat("{perState:'sttDesc',isPromotton:'isPromottonDesc',isFragile:'isFragileDesc'}").format(list);
  740. list = Service.lookup(IFormatService.class).formatEnum(list, "{sttDesc:'PROEQUREL_STATE',isPromottonDesc:'IS_PROMOTION',isFragileDesc:'IS_FRAGILE'}");
  741. //传递数据
  742. res.set(IMINBusinessConstant.F_PAGING_LAY, list);
  743. return res;
  744. }
  745. /**
  746. * 删除货道
  747. *
  748. * @param equId 设备id
  749. * @param perState 状态
  750. * @param session
  751. * @return
  752. * @throws MINBusinessException
  753. */
  754. @MINAction(value = DEL_EQUPRO)
  755. public MINActionResult delEquPro(
  756. @MINParam(key = "equId") String equId,
  757. @MINParam(key = "perRow") String perRow,
  758. @MINParam(key = "perLine") String perLine,
  759. @MINParam(key = "perState") String perState,
  760. MINSession session
  761. ) throws MINBusinessException {
  762. MINActionResult res = new MINActionResult();
  763. //当前时间
  764. String dateTime = DateUtil.getCurrentDateTimeString();
  765. User user = session.getUser();
  766. //操作员id
  767. String uId = user.getId();
  768. //渠道
  769. String channel = user.getChannel();
  770. //校验设备是否正常
  771. VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class)
  772. .getMybatisMapper(VmEquipmentInfMapper.class)
  773. .selectByPrimaryKey(equId);
  774. if (equipmentInf == null) {
  775. throw new MINBusinessException("该设备不存在!");
  776. } else if (equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)) {
  777. throw new MINBusinessException("该设备已销毁!");
  778. }
  779. VmProEquRelExample equRelExample = new VmProEquRelExample();
  780. equRelExample.createCriteria().andEquipmentIdEqualTo(equId)
  781. .andCargoWayRowEqualTo(perRow)
  782. .andCargoWayLineEqualTo(perLine)
  783. .andChannelEqualTo(channel)
  784. .andExeitStateNotEqualTo(Constant.PROEQUREL_STT_02);
  785. List<VmProEquRel> list = Service.lookup(IMINDataBaseService.class)
  786. .getMybatisMapper(VmProEquRelMapper.class)
  787. .selectByExample(equRelExample);
  788. if (list.size() != 0) {
  789. throw new MINBusinessException("此货道无法删除!");
  790. }
  791. //删除货道
  792. String id = Service.lookup(IPublicService.class).getSequence("VM_PROEQUREL_ID");
  793. VmProEquRel proEquRel = new VmProEquRel();
  794. proEquRel.setId(id); //设备商品关联表id
  795. proEquRel.setEquipmentId(equId); //设备id
  796. proEquRel.setCargoWayRow(perRow); //货道层
  797. proEquRel.setCargoWayLine(perLine); //货道列
  798. proEquRel.setUserId(uId); //商户id
  799. proEquRel.setRemarks("货道删除"); //备注
  800. proEquRel.setChannel(channel); //渠道
  801. proEquRel.setCreateUser(uId); //创建人
  802. proEquRel.setCreateTime(dateTime); //创建时间
  803. proEquRel.setModifyUser(uId); //最后修改人
  804. proEquRel.setModifyTime(dateTime); //最后修改时间
  805. proEquRel.setExeitState(Constant.PROEQUREL_STT_01); //状态 01货道删除
  806. Service.lookup(IMINDataBaseService.class)
  807. .getMybatisMapper(VmProEquRelMapper.class)
  808. .insertSelective(proEquRel);
  809. return res;
  810. }
  811. /**
  812. * 删除
  813. *
  814. * @param perId 设备商品关联id
  815. * @param perState 状态
  816. * @param session
  817. * @return
  818. * @throws MINBusinessException
  819. */
  820. @MINAction(value = DEL_PROEQU)
  821. public MINActionResult delProEqu(
  822. @MINParam(key = "perId") String perId,
  823. @MINParam(key = "perState") String perState,
  824. MINSession session
  825. ) throws MINBusinessException {
  826. MINActionResult res = new MINActionResult();
  827. //当前时间
  828. String dateTime = DateUtil.getCurrentDateTimeString();
  829. User user = session.getUser();
  830. //操作员id
  831. String uId = user.getId();
  832. //渠道
  833. // String channel = user.getChannel();
  834. //校验设备是否正常
  835. /*VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class)
  836. .getMybatisMapper(VmEquipmentInfMapper.class)
  837. .selectByPrimaryKey(equId);
  838. if(equipmentInf == null){
  839. throw new MINBusinessException("该设备不存在!");
  840. }else if(equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)){
  841. throw new MINBusinessException("该设备已销毁!");
  842. }
  843. */
  844. VmProEquRel proEquRel = Service.lookup(IMINDataBaseService.class)
  845. .getMybatisMapper(VmProEquRelMapper.class)
  846. .selectByPrimaryKey(perId);
  847. //删除
  848. proEquRel.setId(perId);
  849. proEquRel.setExeitState(Constant.PROEQUREL_STT_02); //状态
  850. proEquRel.setModifyUser(uId); //最后修改人
  851. proEquRel.setModifyTime(dateTime); //最后修改时间
  852. Service.lookup(IMINDataBaseService.class)
  853. .getMybatisMapper(VmProEquRelMapper.class)
  854. .updateByPrimaryKeySelective(proEquRel);
  855. return res;
  856. }
  857. /**
  858. * 查询设备列表
  859. *
  860. * @param equName 设备名称
  861. * @param equState 状态
  862. * @param session
  863. * @return
  864. * @throws MINBusinessException
  865. */
  866. @MINAction(value = QUERY_EQUIPMENT_LINE)
  867. public MINActionResult queryEquipmentLine(
  868. @MINParam(key = "equName") String equName,
  869. @MINParam(key = "machineNo") String machineNo,
  870. @MINParam(key = "temId") String temId,
  871. @MINParam(key = "userName") String userName,
  872. @MINParam(key = "dates") String dates,
  873. @MINParam(key = "equState") String equState,
  874. @MINParam(key = "machineNomax") String machineNomax,
  875. @MINParam(key = "machineNomin") String machineNomin,
  876. @MINParam(key = "page", defaultValue = "1") int page,
  877. @MINParam(key = "limit", defaultValue = "10") int limit,
  878. MINSession session
  879. ) throws MINBusinessException {
  880. MINActionResult res = new MINActionResult();
  881. MINRowBounds rows = new MINRowBounds(page, limit);
  882. User user = session.getUser();
  883. //操作员id
  884. String uId = user.getId();
  885. //渠道
  886. String channel = user.getChannel();
  887. // 查询条件
  888. Map<String, String> map = new HashMap<String, String>();
  889. map.put("channel", "V01");
  890. map.put("equName", equName);
  891. map.put("equState", equState);
  892. map.put("temId", temId);
  893. map.put("userName", userName);
  894. map.put("dates", dates);
  895. map.put("machineNo", machineNo);
  896. map.put("machineNomax", machineNomax);
  897. map.put("machineNomin", machineNomin);
  898. // if(user.getRoleId().equals("10000002")){
  899. // map.put("userId", uId);
  900. // }
  901. if (user.getIdentity().equals("00")) {
  902. map.put("userId", uId);
  903. } else if (user.getIdentity().equals("91")) {
  904. map.put("agentId", uId);
  905. }
  906. List<Map<String, Object>> list = Service.lookup(IMINDataBaseService.class)
  907. .getMybatisMapper(MachineManageMapper.class)
  908. .queryEquipment(map, rows);
  909. //格式化时间和状态
  910. list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime");
  911. list = new MINCopyFormat("{equState:'sttDesc',type:'typeDesc'}").format(list);
  912. list = Service.lookup(IFormatService.class).formatEnum(list, "{sttDesc:'EQUIPMENT_STATE','typeDesc':'GAME_TYPE'}");
  913. //传递数据
  914. res.set(IMINBusinessConstant.F_PAGING_LAY, list);
  915. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows());
  916. return res;
  917. }
  918. /**
  919. * 多选设备复制商品
  920. *
  921. * @param equId 设备id
  922. * @param copyEquId 复制设备id
  923. * @param session
  924. * @return
  925. * @throws MINBusinessException
  926. */
  927. @MINAction(value = ADD_PROEQURELALL_COPY, transaction = IMINTransactionEnum.CMT)
  928. public MINActionResult addProEquRelAllCopy(
  929. @MINParam(key = "equId") String equId,
  930. @MINParam(key = "copyEquId") String copyEquId,
  931. MINSession session
  932. ) throws MINBusinessException {
  933. MINActionResult res = new MINActionResult();
  934. if (equId.indexOf(copyEquId) != -1) {
  935. throw new MINBusinessException("不能选择相同设备!");
  936. }
  937. String[] equIdArr = equId.split(",");
  938. for (int i = 0; i < equIdArr.length; i++) {
  939. //当前时间
  940. String dateTime = DateUtil.getCurrentDateTimeString();
  941. User user = session.getUser();
  942. //操作员id
  943. String userId = user.getId();
  944. //渠道
  945. String channel = "V01";
  946. //校验设备是否正常
  947. VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class)
  948. .getMybatisMapper(VmEquipmentInfMapper.class)
  949. .selectByPrimaryKey(equIdArr[i]);
  950. if (equipmentInf == null) {
  951. throw new MINBusinessException("该设备不存在!");
  952. } else if (equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)) {
  953. throw new MINBusinessException("该设备已销毁!");
  954. }
  955. //查询设备中原有的商品
  956. VmProEquRelExample proEquRelExample = new VmProEquRelExample();
  957. proEquRelExample.createCriteria().andEquipmentIdEqualTo(equIdArr[i])
  958. .andChannelEqualTo(channel)
  959. .andExeitStateEqualTo(Constant.PROEQUREL_STT_00);
  960. List<VmProEquRel> list = Service.lookup(IMINDataBaseService.class)
  961. .getMybatisMapper(VmProEquRelMapper.class)
  962. .selectByExample(proEquRelExample);
  963. for (int j = 0; i < list.size(); j++) {
  964. VmProEquRel equRel = list.get(j);
  965. //设备新增商品
  966. equRel.setExeitState(Constant.PROEQUREL_STT_02); //状态
  967. equRel.setModifyUser(userId); //最后修改人
  968. equRel.setModifyTime(dateTime); //最后修改时间
  969. Service.lookup(IMINDataBaseService.class)
  970. .getMybatisMapper(VmProEquRelMapper.class)
  971. .updateByPrimaryKeySelective(equRel);
  972. }
  973. //查询设备中的商品
  974. VmProEquRelExample proEquRelExample2 = new VmProEquRelExample();
  975. proEquRelExample2.createCriteria().andEquipmentIdEqualTo(copyEquId)
  976. .andChannelEqualTo(channel)
  977. .andExeitStateEqualTo(Constant.PROEQUREL_STT_00);
  978. List<VmProEquRel> list2 = Service.lookup(IMINDataBaseService.class)
  979. .getMybatisMapper(VmProEquRelMapper.class)
  980. .selectByExample(proEquRelExample2);
  981. for (int j = 0; j < list2.size(); j++) {
  982. VmProEquRel equRel2 = list2.get(j);
  983. //设备新增商品
  984. String id = Service.lookup(IPublicService.class).getSequence("VM_PROEQUREL_ID");
  985. equRel2.setId(id); //设备商品关联id
  986. equRel2.setEquipmentId(equIdArr[i]); //设备id
  987. equRel2.setCreateUser(userId); //创建人
  988. equRel2.setCreateTime(dateTime); //创建时间
  989. equRel2.setModifyUser(userId); //最后修改人
  990. equRel2.setModifyTime(dateTime); //最后修改时间
  991. Service.lookup(IMINDataBaseService.class)
  992. .getMybatisMapper(VmProEquRelMapper.class)
  993. .insertSelective(equRel2);
  994. }
  995. }
  996. return res;
  997. }
  998. /**
  999. * 编辑设备
  1000. *
  1001. * @param session
  1002. * @return
  1003. * @throws MINBusinessException
  1004. */
  1005. @MINAction(value = MODIFY_PRODUCT_INF, transaction = IMINTransactionEnum.CMT)
  1006. public MINActionResult modifyProductInf(
  1007. @MINParam(key = "id") String id,
  1008. @MINParam(key = "name") String name,
  1009. @MINParam(key = "ioiServicePrivider") String ioiServicePrivider,
  1010. @MINParam(key = "ioiCardNumber") String ioiCardNumber,
  1011. @MINParam(key = "address") String address,
  1012. @MINParam(key = "versionType") String versionType,
  1013. @MINParam(key = "equType") String equType,
  1014. @MINParam(key = "wcAccount") String wcAccount,
  1015. @MINParam(key = "zfbAccount") String zfbAccount,
  1016. @MINParam(key = "charge") String charge,
  1017. @MINParam(key = "payeeNo") String payeeNo,
  1018. @MINParam(key = "creditChannel") String creditChannel,
  1019. @MINParam(key = "payment") String payment,
  1020. @MINParam(key = "paymentType") String paymentType,
  1021. @MINParam(key = "exchangeRate") String exchangeRate,
  1022. @MINParam(key = "supportBalance") String supportBalance,
  1023. MINSession session) throws MINBusinessException {
  1024. MINActionResult res = new MINActionResult();
  1025. //获取当前时间
  1026. String nowTime = DateUtil.getCurrentDateTimeString();
  1027. // 获取操作员信息
  1028. User user = session.getUser();
  1029. VmEquipmentInf pro = new VmEquipmentInf();
  1030. pro.setId(id);
  1031. if (CommonUtil.isEmpty(name)){
  1032. pro.setName("无人售货机");
  1033. }else{
  1034. pro.setName(name);
  1035. }
  1036. pro.setIotCardNumber(ioiCardNumber);
  1037. pro.setIotServiceProvider(ioiServicePrivider);
  1038. pro.setModifyUser(user.getId());
  1039. pro.setModifyTime(nowTime);
  1040. pro.setAddress(address);
  1041. pro.setEquType(equType);
  1042. pro.setWcAccount(wcAccount);
  1043. pro.setZfbAccount(zfbAccount);
  1044. pro.setCharge(charge);
  1045. pro.setPayeeNo(payeeNo);
  1046. pro.setCreditChannel(creditChannel);
  1047. pro.setPayment(payment);
  1048. pro.setPaymentType(paymentType);
  1049. pro.setExchangeRate(exchangeRate);
  1050. pro.setSupportBalance(supportBalance);
  1051. pro.setModifyUser(user.getId());
  1052. pro.setModifyTime(nowTime);
  1053. Service.lookup(IMINDataBaseService.class)
  1054. .getMybatisMapper(VmEquipmentInfMapper.class)
  1055. .updateByPrimaryKeySelective(pro);
  1056. /*// 记录操作日志
  1057. String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id;
  1058. Service.lookup(ILogService.class).logging(session, logInfo);*/
  1059. return res;
  1060. }
  1061. /**
  1062. * 开启/关闭音乐
  1063. *
  1064. * @param id 机器id
  1065. * @return
  1066. * @throws Exception
  1067. */
  1068. @MINAction(value = CLOSE_SONG)
  1069. public MINActionResult closeSong(
  1070. @MINParam(key = "id") String id,
  1071. @MINParam(key = "status") String status,
  1072. MINSession session) throws Exception {
  1073. MINActionResult res = new MINActionResult();
  1074. User user = session.getUser();
  1075. if (CommonUtil.isEmpty(id)){
  1076. throw new MINBusinessException("机器id上送为空!");
  1077. }
  1078. //校验设备是否正常
  1079. VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class)
  1080. .getMybatisMapper(VmEquipmentInfMapper.class)
  1081. .selectByPrimaryKey(id);
  1082. if (equipmentInf == null) {
  1083. throw new MINBusinessException("该设备不存在!");
  1084. } else if (equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)) {
  1085. throw new MINBusinessException("该设备已销毁!");
  1086. }
  1087. VmEquipmentInf pro = new VmEquipmentInf();
  1088. pro.setId(id);
  1089. pro.setSongStatus(status);//关闭
  1090. Service.lookup(IMINDataBaseService.class)
  1091. .getMybatisMapper(VmEquipmentInfMapper.class)
  1092. .updateByPrimaryKeySelective(pro);
  1093. return res;
  1094. }
  1095. /**
  1096. * 一键补货
  1097. * @param equId 设备id
  1098. * @param session
  1099. * @return
  1100. * @throws MINBusinessException
  1101. */
  1102. @MINAction(value = ADD_PROEQUREL_NUM, transaction = IMINTransactionEnum.CMT)
  1103. public MINActionResult addProEquRelNum(
  1104. @MINParam(key = "equId") String equId,
  1105. @MINParam(key = "proNum") String proNum,
  1106. @MINParam(key = "proState") String proState,
  1107. MINSession session
  1108. ) throws MINBusinessException {
  1109. MINActionResult res = new MINActionResult();
  1110. //当前时间
  1111. String dateTime = DateUtil.getCurrentDateTimeString();
  1112. User user = session.getUser();
  1113. //操作员id
  1114. String userId = user.getId();
  1115. //渠道
  1116. String channel = user.getChannel();
  1117. //校验设备是否正常
  1118. VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class)
  1119. .getMybatisMapper(VmEquipmentInfMapper.class)
  1120. .selectByPrimaryKey(equId);
  1121. if(equipmentInf == null){
  1122. throw new MINBusinessException("该设备不存在!");
  1123. }else if(equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)){
  1124. throw new MINBusinessException("该设备已销毁!");
  1125. }
  1126. //查询设备中的商品
  1127. VmProEquRelExample proEquRelExample = new VmProEquRelExample();
  1128. proEquRelExample.createCriteria().andEquipmentIdEqualTo(equId)
  1129. .andChannelEqualTo("V01")
  1130. .andExeitStateEqualTo(Constant.PROEQUREL_STT_00);
  1131. List<VmProEquRel> list2 = Service.lookup(IMINDataBaseService.class)
  1132. .getMybatisMapper(VmProEquRelMapper.class)
  1133. .selectByExample(proEquRelExample);
  1134. for (int i = 0; i < list2.size(); i++) {
  1135. VmProEquRel equRel = list2.get(i);
  1136. if(proState.equals("222")) {
  1137. equRel.setProductNums(equRel.getCargoWayNums()); //商品余量修改为货道容量
  1138. }else{
  1139. equRel.setProductNums(proNum);
  1140. }
  1141. equRel.setModifyUser(userId); //最后修改人
  1142. equRel.setModifyTime(dateTime); //最后修改时间
  1143. Service.lookup(IMINDataBaseService.class)
  1144. .getMybatisMapper(VmProEquRelMapper.class)
  1145. .updateByPrimaryKeySelective(equRel);
  1146. }
  1147. return res;
  1148. }
  1149. /**
  1150. * 一键设置商品价格
  1151. * @param equId 设备id
  1152. * @param sallPrice 售货价
  1153. * @param gamePrice 游戏价
  1154. * @param costPrice 成本价
  1155. * @param type 游戏类型
  1156. * @param isPromotton 是否促销
  1157. * @param promottonPrice 促销价
  1158. * @param session
  1159. * @return
  1160. * @throws MINBusinessException
  1161. */
  1162. @MINAction(value = EDIT_PROEQUREL_PRICE, transaction = IMINTransactionEnum.CMT)
  1163. public MINActionResult editProEquRelPrice(
  1164. @MINParam(key = "equId") String equId,
  1165. @MINParam(key = "sallPrice") String sallPrice,
  1166. @MINParam(key = "gamePrice") String gamePrice,
  1167. @MINParam(key = "costPrice") String costPrice,
  1168. @MINParam(key = "type") String type,
  1169. @MINParam(key = "isPromotton") String isPromotton,
  1170. @MINParam(key = "promottonPrice") String promottonPrice,
  1171. MINSession session
  1172. ) throws MINBusinessException {
  1173. MINActionResult res = new MINActionResult();
  1174. //当前时间
  1175. String dateTime = DateUtil.getCurrentDateTimeString();
  1176. User user = session.getUser();
  1177. //操作员id
  1178. String userId = user.getId();
  1179. //渠道
  1180. String channel = user.getChannel();
  1181. //校验设备是否正常
  1182. VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class)
  1183. .getMybatisMapper(VmEquipmentInfMapper.class)
  1184. .selectByPrimaryKey(equId);
  1185. if(equipmentInf == null){
  1186. throw new MINBusinessException("该设备不存在!");
  1187. }else if(equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)){
  1188. throw new MINBusinessException("该设备已销毁!");
  1189. }
  1190. int comcosAndsal = CommonUtil.compare(costPrice, sallPrice);
  1191. int comcosAndgam = CommonUtil.compare(costPrice, gamePrice);
  1192. int comgamAndsal = CommonUtil.compare(gamePrice, sallPrice);
  1193. // int comcosAndpro = CommonUtil.compare(costPrice, promottonPrice);
  1194. int comproAndsal = CommonUtil.compare(promottonPrice, sallPrice);
  1195. if (comcosAndsal == 1 || comcosAndsal == 0) {
  1196. throw new MINBusinessException("成本价不能大于或等于售货价!");
  1197. }
  1198. /* if (comcosAndgam == 1 || comcosAndgam == 0) {
  1199. throw new MINBusinessException("成本价不能大于或等于游戏价!");
  1200. }
  1201. if (comgamAndsal == 1 || comgamAndsal == 0) {
  1202. throw new MINBusinessException("游戏价不能大于或等于售货价!");
  1203. }*/
  1204. // if (comcosAndpro == 1 || comcosAndpro == 0) {
  1205. // throw new MINBusinessException("成本价不能大于或等于促销价!");
  1206. // }
  1207. if (comproAndsal == 1 || comproAndsal == 0) {
  1208. throw new MINBusinessException("促销价不能大于或等于售货价!");
  1209. }
  1210. //查询设备中的商品
  1211. VmProEquRelExample proEquRelExample = new VmProEquRelExample();
  1212. proEquRelExample.createCriteria().andEquipmentIdEqualTo(equId)
  1213. .andChannelEqualTo("V01")
  1214. .andExeitStateEqualTo(Constant.PROEQUREL_STT_00);
  1215. List<VmProEquRel> list2 = Service.lookup(IMINDataBaseService.class)
  1216. .getMybatisMapper(VmProEquRelMapper.class)
  1217. .selectByExample(proEquRelExample);
  1218. for (int i = 0; i < list2.size(); i++) {
  1219. VmProEquRel equRel = list2.get(i);
  1220. equRel.setSallPrice(sallPrice); //售货价
  1221. equRel.setGamePrice(gamePrice); //游戏价
  1222. equRel.setCostPrice(costPrice); //成本价
  1223. equRel.setIsPromotion(isPromotton); //是否促销
  1224. equRel.setPromotionPrice(promottonPrice); //促销价
  1225. equRel.setGameType(type); //游戏类型
  1226. equRel.setModifyUser(userId); //最后修改人
  1227. equRel.setModifyTime(dateTime); //最后修改时间
  1228. Service.lookup(IMINDataBaseService.class)
  1229. .getMybatisMapper(VmProEquRelMapper.class)
  1230. .updateByPrimaryKeySelective(equRel);
  1231. }
  1232. return res;
  1233. }
  1234. /**
  1235. * 生成包含字符串信息的二维码图片
  1236. * @param flash 是否刷新
  1237. */
  1238. @MINAction(value = CREATE_QRCODE, transaction = IMINTransactionEnum.CMT)
  1239. public static MINActionResult createQrCode(
  1240. @MINParam(key = "flash") String flash,
  1241. @MINParam(key = "equId") String equId,
  1242. @MINParam(key = "equType") String equType,
  1243. MINSession session)throws MINBusinessException, FileNotFoundException, WriterException, IOException {
  1244. MINActionResult res = new MINActionResult();
  1245. //如果equType
  1246. //获取当前用户信息
  1247. User u = session.getUser();
  1248. //获取用户id
  1249. String userId = u.getBranchId();
  1250. //刷新,生成
  1251. //开发环境修改配置
  1252. String basePath = "/home/images/"+ userId+".jpg"; //与nginx配置相同
  1253. String os = System.getProperty("os.name");
  1254. if(os.toLowerCase().startsWith("win")){
  1255. System.out.println(os + " can't gunzip");
  1256. basePath = "D:/images/"+ userId+".jpg"; //与nginx配置相同
  1257. }
  1258. File file = new File(basePath);
  1259. //获取父目录
  1260. File fileParent = file.getParentFile();
  1261. //判断是否存在
  1262. if (!fileParent.exists()) {
  1263. fileParent.mkdirs();
  1264. }
  1265. //获取渠道号
  1266. String channel = "V01";
  1267. String address = Service.lookup(IPropertiesService.class)
  1268. .getSystemProperties().get(channel+"_TO_MACHINE_ERWERMA").getKey();// 为nginx根路径
  1269. // 加密客户号
  1270. OutputStream outputStream = new FileOutputStream(file);
  1271. String serviceUrl = Service.lookup(IPropertiesService.class)
  1272. .getSystemProperties().get(channel+"_TO_MACHINE_ERWERMA").getKey();
  1273. serviceUrl = "http://".concat(serviceUrl.concat("/admin/h5/index.html?equId=").concat(equId).concat("&equType=").concat(equType));
  1274. //String urlString = URLEncoder.encode(, "GBK");
  1275. // 生成二维码图片到本地
  1276. try {
  1277. EquCodeCreateUtil.createQrCode(outputStream,serviceUrl,900,"JPEG");
  1278. } catch (com.google.zxing.WriterException e) {
  1279. // TODO Auto-generated catch block
  1280. e.printStackTrace();
  1281. }
  1282. outputStream.close();
  1283. // 上传图片到服务器
  1284. InputStream inputSteam = new FileInputStream(file);
  1285. String url = UpLoadFile.uploadImg(inputSteam,"jpg",channel,"00");
  1286. inputSteam.close();
  1287. // 删除本地图片
  1288. file.delete();
  1289. res.set("url", url);
  1290. VmEquipmentInf vmEquipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByPrimaryKey(equId);
  1291. if (null != vmEquipmentInf){
  1292. vmEquipmentInf.setUrlCode(url);
  1293. Service.lookup(IMINDataBaseService.class)
  1294. .getMybatisMapper(VmEquipmentInfMapper.class)
  1295. .updateByPrimaryKeySelective(vmEquipmentInf);
  1296. }
  1297. return res;
  1298. }
  1299. /**
  1300. * 补货
  1301. * @param perId 设备id
  1302. * @param session
  1303. * @return
  1304. * @throws MINBusinessException
  1305. */
  1306. @MINAction(value = EDIT_PROEQUREL_NUM)
  1307. public MINActionResult editProEquRelNum(
  1308. @MINParam(key = "perId") String perId,
  1309. @MINParam(key = "proNum") String proNum,
  1310. MINSession session
  1311. ) throws MINBusinessException {
  1312. MINActionResult res = new MINActionResult();
  1313. //当前时间
  1314. String dateTime = DateUtil.getCurrentDateTimeString();
  1315. User user = session.getUser();
  1316. //操作员id
  1317. String userId = user.getId();
  1318. //渠道
  1319. // String channel = user.getChannel();
  1320. //校验设备是否正常
  1321. VmProEquRel equRel = Service.lookup(IMINDataBaseService.class)
  1322. .getMybatisMapper(VmProEquRelMapper.class)
  1323. .selectByPrimaryKey(perId);
  1324. String proNumall = equRel.getCargoWayNums();
  1325. int comcosAndsal = CommonUtil.compare(proNum, proNumall);
  1326. if (comcosAndsal == 1 ) {
  1327. throw new MINBusinessException("补货量不能大于货道容量!");
  1328. }
  1329. if(equRel == null||equRel.getExeitState().equals(Constant.PROEQUREL_STT_02)){
  1330. throw new MINBusinessException("设备中该货物不存在!");
  1331. }
  1332. equRel.setProductNums(proNum); //商品余量修改为货道容量
  1333. equRel.setModifyUser(userId); //最后修改人
  1334. equRel.setModifyTime(dateTime); //最后修改时间
  1335. Service.lookup(IMINDataBaseService.class)
  1336. .getMybatisMapper(VmProEquRelMapper.class)
  1337. .updateByPrimaryKeySelective(equRel);
  1338. return res;
  1339. }
  1340. /**
  1341. * 添加设备
  1342. *
  1343. * @param session
  1344. * @return
  1345. * @throws MINBusinessException
  1346. */
  1347. @MINAction(value = DELETE_EQU, transaction = IMINTransactionEnum.CMT)
  1348. public MINActionResult deleteEqu(
  1349. @MINParam(key = "startEquCode") String startEquCode,
  1350. @MINParam(key = "endEquCode") String endEquCode,
  1351. MINSession session) throws MINBusinessException {
  1352. MINActionResult res = new MINActionResult();
  1353. //获取当前时间
  1354. String nowTime = DateUtil.getCurrentDateTimeString();
  1355. // 获取操作员信息
  1356. User user = session.getUser();
  1357. if (CommonUtil.isEmpty(startEquCode)) {
  1358. throw new MINBusinessException("起始解绑机台号为空");
  1359. }
  1360. if (!CommonUtil.isEmpty(endEquCode)) {
  1361. int code = CommonUtil.compare(startEquCode,endEquCode);
  1362. if (code == 0 || code == 1){
  1363. throw new MINBusinessException("起始解绑机台号不能大于等于结束解绑机台号");
  1364. }
  1365. for (int i = Integer.parseInt(startEquCode);i <= Integer.parseInt(endEquCode);i++){
  1366. VmEquipmentInfExample example = new VmEquipmentInfExample();
  1367. example.createCriteria().andMachineNoEqualTo(String.valueOf(i));
  1368. List<VmEquipmentInf> vmEquipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByExample(example);
  1369. if (vmEquipmentInf != null && vmEquipmentInf.size() > 0){
  1370. Service.lookup(IMINDataBaseService.class)
  1371. .getMybatisMapper(VmEquipmentInfMapper.class)
  1372. .deleteByPrimaryKey(vmEquipmentInf.get(0).getId());
  1373. }
  1374. }
  1375. }else{
  1376. VmEquipmentInfExample example = new VmEquipmentInfExample();
  1377. example.createCriteria().andMachineNoEqualTo(startEquCode);
  1378. List<VmEquipmentInf> vmEquipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByExample(example);
  1379. if (vmEquipmentInf != null && vmEquipmentInf.size() > 0){
  1380. Service.lookup(IMINDataBaseService.class)
  1381. .getMybatisMapper(VmEquipmentInfMapper.class)
  1382. .deleteByPrimaryKey(vmEquipmentInf.get(0).getId());
  1383. }
  1384. }
  1385. /*// 记录操作日志
  1386. String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id;
  1387. Service.lookup(ILogService.class).logging(session, logInfo);*/
  1388. return res;
  1389. }
  1390. /**
  1391. * 添加设备货道
  1392. *
  1393. * @param session
  1394. * @return
  1395. * @throws MINBusinessException
  1396. */
  1397. @MINAction(value = ADD_PRO_EQU_REL, transaction = IMINTransactionEnum.CMT)
  1398. public MINActionResult addProEquRelLineRow(
  1399. @MINParam(key = "line") String line,
  1400. @MINParam(key = "row") String row,
  1401. @MINParam(key = "equId") String equId,
  1402. MINSession session) throws MINBusinessException {
  1403. MINActionResult res = new MINActionResult();
  1404. //获取当前时间
  1405. String nowTime = DateUtil.getCurrentDateTimeString();
  1406. // 获取操作员信息
  1407. User user = session.getUser();
  1408. VmProEquRelExample example = new VmProEquRelExample();
  1409. example.createCriteria().andIdEqualTo(equId).andCargoWayLineEqualTo(CommonUtil.subtract(line,"1")).andCargoWayRowEqualTo(CommonUtil.subtract(row,"1"));
  1410. List<VmProEquRel> List = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmProEquRelMapper.class).selectByExample(example);
  1411. if (List.size()>0){
  1412. throw new MINBusinessException("货道已存在");
  1413. }
  1414. String id = Service.lookup(IPublicService.class).getSequence("VM_PROEQUREL_ID");
  1415. VmProEquRel vmProEquRel = new VmProEquRel();
  1416. vmProEquRel.setId(id);
  1417. vmProEquRel.setEquipmentId(equId);
  1418. vmProEquRel.setCargoWayLine(CommonUtil.subtract(line,"1"));
  1419. vmProEquRel.setCargoWayRow(CommonUtil.subtract(row,"1"));
  1420. vmProEquRel.setExeitState("00");
  1421. vmProEquRel.setCreateTime(nowTime);
  1422. vmProEquRel.setCreateUser(user.getId());
  1423. Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmProEquRelMapper.class).insertSelective(vmProEquRel);
  1424. /*// 记录操作日志
  1425. String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id;
  1426. Service.lookup(ILogService.class).logging(session, logInfo);*/
  1427. return res;
  1428. }
  1429. }