MachineManageAction.java 78 KB

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