package com.minpay.mt.machine.action; import com.itextpdf.text.pdf.qrcode.WriterException; import com.min.util.CommonUtil; import com.minpay.common.bean.User; import com.minpay.common.constant.Constant; import com.minpay.common.format.IFormatService; import com.minpay.common.service.ILogService; import com.minpay.common.service.IPropertiesService; import com.minpay.common.service.IPublicService; import com.minpay.common.util.DateUtil; import com.minpay.common.util.UpLoadFile; import com.minpay.db.table.mapper.ImBranchMapper; import com.minpay.db.table.mapper.VmEquipmentInfMapper; import com.minpay.db.table.mapper.VmHlAccountMapper; import com.minpay.db.table.mapper.VmProEquRelMapper; import com.minpay.db.table.model.*; import com.minpay.db.table.own.mapper.MachineManageMapper; import com.minpay.huicai.util.EquCodeCreateUtil; import com.mysql.jdbc.StringUtils; import com.startup.minpay.frame.business.IMINAction; import com.startup.minpay.frame.business.res.MINActionResult; import com.startup.minpay.frame.constant.IMINBusinessConstant; import com.startup.minpay.frame.constant.IMINTransactionEnum; import com.startup.minpay.frame.data.format.MINCopyFormat; import com.startup.minpay.frame.exception.MINBusinessException; import com.startup.minpay.frame.jdbc.MINRowBounds; import com.startup.minpay.frame.service.base.IMINDataBaseService; import com.startup.minpay.frame.service.base.Service; import com.startup.minpay.frame.session.MINSession; import com.startup.minpay.frame.target.MINAction; import com.startup.minpay.frame.target.MINComponent; import com.startup.minpay.frame.target.MINParam; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import java.io.*; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 设备管理 * @author pangjl * 20190325 */ @MINComponent public class MachineManageAction implements IMINAction { /** * 查看设备 */ public final static String QUERY_EQUMENT_INF = "queryEqumentInf"; /** * 添加设备 */ public final static String ADD_PRODUCT_INF = "addMachine"; /** * 修改设备 */ public final static String MODIFY_PRODUCT_INF = "modifyProductInf"; /** * 更改设备状态 */ public final static String MODIFY_PRODUCT_STATE = "modifyProductState"; /** * 查询设备中商品 */ public final static String QUERY_PROEQUREL = "queryProEquRel"; /** * 查询设备中商品 */ public final static String QUERY_PROEQURELPAGE = "queryProEquRelPage"; /** * 查看正常状态商品 */ public final static String QUERY_PRODUCTZ = "queryProductz"; /** * 设备添加商品 */ public final static String ADD_PROEQUREL = "addProEquRel"; /** * 修改设备商品 */ public final static String EDIT_PROEQUREL = "editProEquRel"; /** * 查询编辑设备中商品 */ public final static String QUERY_PROEQU = "queryProEqu"; /** * 删除货道 */ public final static String DEL_EQUPRO = "delEquPro"; /** * 删除设备中商品 */ public final static String DEL_PROEQU = "delProEqu"; /** * 查询设备列表 */ public final static String QUERY_EQUIPMENT_LINE = "queryEquipmentLine"; /** * 多选设备复制商品 */ public final static String ADD_PROEQURELALL_COPY = "addProEquRelAllCopy"; /** * 关闭音乐 */ public final static String CLOSE_SONG = "closeSong"; /**一键补货*/ public final static String ADD_PROEQUREL_NUM = "addProEquRelNum"; /**一键设置商品价格*/ public final static String EDIT_PROEQUREL_PRICE = "editProEquRelPrice"; /** 生成包含字符串信息的二维码图片**/ public static final String CREATE_QRCODE = "createQrCode"; /**补货*/ public final static String EDIT_PROEQUREL_NUM = "editProEquRelNum"; /**解绑机台号*/ public final static String DELETE_EQU = "deleteEqu"; /**生成指定机器指定行列的货道*/ public final static String ADD_PRO_EQU_REL = "addProEquRelLineRow"; /**查询商户关联页面*/ public final static String QUERY_FUNCTION = "queryFunction"; /**清空累计金额*/ public final static String EMPTY_PROEQUREL = "emptyProEquRel"; /** 收款商户号信息查询 */ public final static String TENCENTMANAGE_QUERY = "businessNumManageQuery"; /** 商户号信息查询 */ public final static String QUERY_BRANCH = "queryBranch"; /** 绑定商户号 */ public final static String BIND_BRANCH = "bindBranch"; private boolean contains; /** * 查看设备 * * @param createUser 添加人 * @param page * @param limit * @return * @throws Exception */ @MINAction(value = QUERY_EQUMENT_INF) public MINActionResult queryEqumentInf( @MINParam(key = "machineId") String machineId, @MINParam(key = "state") String state, @MINParam(key = "machineName") String machineName, @MINParam(key = "mchntId") String mchntId, @MINParam(key = "equType") String equType, @MINParam(key = "createUser") String createUser, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "3") int limit, MINSession session) throws Exception { MINActionResult res = new MINActionResult(); User user = session.getUser(); String passwardKey = Service.lookup(IPropertiesService.class) .getSystemProperties().get("WALLET_TO_METTING_PASSWORD_KEY").getKey(); Map map = new HashMap(); map.put("id", machineId); if(Constant.DEFAULT_INSTITUTIONS.equals( user.getBranchId())){ map.put("mchntId", mchntId); }else{ map.put("mchntId", user.getBranchId()); } map.put("equType", equType); map.put("machineName", machineName); map.put("createUser", createUser); map.put("state", state); map.put("channel", user.getChannel());//渠道号 //验证操作员权限 MINRowBounds rows = new MINRowBounds(page, limit); //执行查询 List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(MachineManageMapper.class) .machineInf(map, rows); List> listb = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(MachineManageMapper.class) .machineInf(map); //在线数 int online = listb.stream().filter(item -> item.get("state").equals("00")).collect(Collectors.toList()).size(); int unOnline = listb.stream().filter(item -> item.get("state").equals("01")).collect(Collectors.toList()).size(); //格式化时间和状态 list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime"); list = new MINCopyFormat("{state:'stateDesc',equType :'equTypeDesc'}").format(list); list = Service.lookup(IFormatService.class).formatEnum(list, "{stateDesc:'EQUIPMENT_STATE',equTypeDesc:'EQUIPMENT_TYPE'}"); //返回数据 res.set(IMINBusinessConstant.F_PAGING_LAY, list); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows()); res.set("online",String.valueOf(online)); res.set("unOnline",String.valueOf(unOnline)); return res; } /** * 添加设备 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = ADD_PRODUCT_INF, transaction = IMINTransactionEnum.CMT) public MINActionResult addMachine( @MINParam(key = "equCode") String equCode, @MINParam(key = "account") String account, @MINParam(key = "temLine") String temLine, @MINParam(key = "temRow") String temRow, MINSession session) throws MINBusinessException, IOException { MINActionResult res = new MINActionResult(); //获取当前时间 String nowTime = DateUtil.getCurrentDateTimeString(); // 获取操作员信息 User user = session.getUser(); if (CommonUtil.isEmpty(equCode)) { throw new MINBusinessException("起始机台号为空"); } if (CommonUtil.isEmpty(account)) { throw new MINBusinessException("生成数量为空"); } if (CommonUtil.isEmpty(temLine)) { throw new MINBusinessException("生成货道行数量为空"); } if (CommonUtil.isEmpty(temRow)) { throw new MINBusinessException("生成货道列数量为空"); } int size = Integer.parseInt(account); VmEquipmentInfExample example = new VmEquipmentInfExample(); example.createCriteria().andMachineNoEqualTo(equCode).andStateEqualTo("00"); List vmEquipmentInfList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByExample(example); if (vmEquipmentInfList.size() > 0) { throw new MINBusinessException(equCode + "机台号已存在"); } for (int j = 1; j < size; j++) { VmEquipmentInfExample examples = new VmEquipmentInfExample(); examples.createCriteria().andMachineNoEqualTo(CommonUtil.add(equCode, String.valueOf(j))).andStateEqualTo("00"); List vmEquipmentInfLists = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByExample(examples); if (vmEquipmentInfLists.size() > 0) { throw new MINBusinessException(equCode + "机台号已存在"); } } //获取当前用户信息 User u = session.getUser(); //获取用户id String userId = u.getBranchId(); //开发环境修改配置 String basePath = "/home/images/"+ userId+".jpg"; //与nginx配置相同 String os = System.getProperty("os.name"); if(os.toLowerCase().startsWith("win")){ System.out.println(os + " can't gunzip"); basePath = "D:/images/"+ userId+".jpg"; //与nginx配置相同 } String id = Service.lookup(IPublicService.class).getSequence("EQU_MACHINE_NO"); File file = new File(basePath); //获取父目录 File fileParent = file.getParentFile(); //判断是否存在 if (!fileParent.exists()) { fileParent.mkdirs(); } //获取渠道号 String channel = "V01"; // 加密客户号 OutputStream outputStream = new FileOutputStream(file); String serviceUrl = Service.lookup(IPropertiesService.class) .getSystemProperties().get(channel+"_TO_MACHINE_ERWERMA").getKey(); serviceUrl = "http://".concat(serviceUrl.concat("/admin/h5/index.html?equId=").concat(id)); //String urlString = URLEncoder.encode(, "GBK"); // 生成二维码图片到本地 try { EquCodeCreateUtil.createQrCode(outputStream,serviceUrl,900,"JPEG"); } catch (com.google.zxing.WriterException e) { // TODO Auto-generated catch block e.printStackTrace(); } outputStream.close(); // 上传图片到服务器 InputStream inputSteam = new FileInputStream(file); String ambient = Service.lookup(IPublicService.class) .getSysParValue("AMBIENT");//当前环境 FileItem fileItem = createFileItem(file ,"itemFileName"); Map map = null; if("00".equals(ambient)){//测试 map =Service.lookup(IPublicService.class).uploadFile(fileItem, "00", 0, true,"V01"); } if("01".equals(ambient)){//生产 map =Service.lookup(IPublicService.class).uploadFileBD(fileItem, "00", 0, true,"V01"); } //String url = UpLoadFile.uploadImg(inputSteam,"jpg",channel,"00"); String url = String.valueOf(map.get("url")); inputSteam.close(); // 删除本地图片 file.delete(); VmEquipmentInf pro = new VmEquipmentInf(); pro.setId(id); pro.setMachineNo(equCode); pro.setImeiAddr(equCode); pro.setChannel("V01"); pro.setState("01"); pro.setCreateUser(user.getId()); pro.setCreateTime(nowTime); pro.setRows(temRow); pro.setLines(temLine); pro.setUrlCode(url); pro.setEquType("00"); //默认支付盒子售货机 pro.setBranchid(Constant.DEFAULT_INSTITUTIONS); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .insertSelective(pro); for (int i = 1; i < size; i++) { String ids = Service.lookup(IPublicService.class).getSequence("EQU_MACHINE_NO"); serviceUrl = "http://".concat(serviceUrl.concat("/admin/h5/index.html?equId=").concat(ids)); //String urlString = URLEncoder.encode(, "GBK"); OutputStream outputStreams = new FileOutputStream(file); // 生成二维码图片到本地 try { EquCodeCreateUtil.createQrCode(outputStreams,serviceUrl,900,"JPEG"); } catch (com.google.zxing.WriterException e) { // TODO Auto-generated catch block e.printStackTrace(); } outputStreams.close(); InputStream inputSteams = new FileInputStream(file); FileItem fileItemb = createFileItem(file ,"itemFileName"); Map mapb = null; if("00".equals(ambient)){//测试 mapb =Service.lookup(IPublicService.class).uploadFile(fileItemb, "00", 0, true,"V01"); } if("01".equals(ambient)){//生产 mapb =Service.lookup(IPublicService.class).uploadFileBD(fileItemb, "00", 0, true,"V01"); } //String url = UpLoadFile.uploadImg(inputSteam,"jpg",channel,"00"); url = String.valueOf(mapb.get("url")); //url = UpLoadFile.uploadImg(inputSteams,"jpg",channel,"00"); inputSteams.close(); // 删除本地图片 file.delete(); VmEquipmentInf pros = new VmEquipmentInf(); pros.setId(ids); pros.setChannel("V01"); pros.setMachineNo(CommonUtil.add(equCode, String.valueOf(i))); pros.setImeiAddr(CommonUtil.add(equCode, String.valueOf(i))); pros.setState("01"); pros.setCreateUser(user.getId()); pros.setCreateTime(nowTime); pros.setRows(temRow); pros.setLines(temLine); pros.setUrlCode(url); pros.setBranchid(Constant.DEFAULT_INSTITUTIONS); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .insertSelective(pros); } /*// 记录操作日志 String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id; Service.lookup(ILogService.class).logging(session, logInfo);*/ return res; } /** * 查询设备中商品 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = QUERY_PROEQUREL) public MINActionResult queryProEquRel( @MINParam(key = "equId") String equId, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); User user = session.getUser(); //渠道 String channel = user.getChannel(); // 查询条件 Map map = new HashMap(); map.put("channel", "V01"); map.put("equId", equId); List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(MachineManageMapper.class) .queryProEquRel(map); //格式化时间和状态 list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime"); list = new MINCopyFormat("{perState:'sttDesc',isPromotton:'isPromottonDesc',isFragile:'isFragileDesc',type:'typeDesc'}").format(list); list = Service.lookup(IFormatService.class).formatEnum(list, "{sttDesc:'PROEQUREL_STATE',isPromottonDesc:'IS_PROMOTION',typeDesc:'GAME_SETUP_TYPE'}"); //传递数据 res.set(IMINBusinessConstant.F_PAGING_LAY, list); return res; } /** * 查看商品 * * @param name 商品名称 * @param brandName 品牌名称 * @param model 商品型号 * @param createUser 添加人 * @param dates 添加时间 * @param page * @param limit * @return * @throws MINBusinessException */ @MINAction(value = QUERY_PRODUCTZ) public MINActionResult queryProductz( @MINParam(key = "name") String name, @MINParam(key = "model") String model, @MINParam(key = "dates") String dates, @MINParam(key = "state") String state, @MINParam(key = "brandName") String brandName, @MINParam(key = "categoryId") String categoryId, @MINParam(key = "createUser") String createUser, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "3") int limit, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); User user = session.getUser(); Map map = new HashMap(); //按商品名称,商品品牌进行模糊查询 map.put("name", name); //商品名称 map.put("state", state);//状态 map.put("model", model); map.put("dates", dates); map.put("brandName", brandName); map.put("createUser", createUser); map.put("channel", "V01");//渠道号 map.put("category", categoryId);//分类 //验证操作员权限 if ("00".equals(user.getIdentity())) { map.put("userId", user.getId()); } /* if("10000002".equals(user.getRoleId())){ map.put("userId",user.getId()); }*/ //分页 MINRowBounds rows = new MINRowBounds(page, limit); //执行查询 List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(MachineManageMapper.class) .queryProductz(map, rows); //格式化时间和状态 list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime"); list = new MINCopyFormat("{history:'historyDesc',state:'stateDesc',source:'sourceDesc'}").format(list); list = Service.lookup(IFormatService.class).formatEnum(list, "{historyDesc:'PRODUCT_HISTORY',stateDesc:'PRODUCT_STATE',sourceDesc:'PRODUCT_SOURCE'}"); //返回数据 res.set(IMINBusinessConstant.F_PAGING_LAY, list); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows()); return res; } /** * 设备添加商品 * * @param perRow 货道层 * @param perLine 货道列 * @param perNum 货道容量 * @param numbers 商品余量 * @param sallPrice 售货价 * @param gamePrice 游戏价 * @param costPrice 成本价 * @param isPromotton 是否促销 * @param promottonPrice 促销价 * @param isFragile 是否易碎 * @param perRemarks 备注 * @param proId 商品id * @param equId 设备id * @param session * @return * @throws MINBusinessException */ @MINAction(value = ADD_PROEQUREL) public MINActionResult addProEquRel( @MINParam(key = "aisle") String aisle, @MINParam(key = "perRow") String perRow, @MINParam(key = "perLine") String perLine, @MINParam(key = "perNum") String perNum, @MINParam(key = "numbers") String numbers, @MINParam(key = "sallPrice") String sallPrice, @MINParam(key = "gamePrice") String gamePrice, @MINParam(key = "costPrice") String costPrice, @MINParam(key = "isPromotton") String isPromotton, @MINParam(key = "promottonPrice") String promottonPrice, @MINParam(key = "type") String type, @MINParam(key = "isFragile") String isFragile, @MINParam(key = "perRemarks") String perRemarks, @MINParam(key = "proId") String proId, @MINParam(key = "equId") String equId, @MINParam(key = "luck") String luck, @MINParam(key = "drawAmount") String drawAmount, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); //当前时间 String dateTime = DateUtil.getCurrentDateTimeString(); User user = session.getUser(); //操作员id String uId = user.getId(); //渠道 String channel = user.getChannel(); //校验设备是否正常 VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByPrimaryKey(equId); if (equipmentInf == null) { throw new MINBusinessException("该设备不存在!"); } else if (equipmentInf.getState().equals("03")) { throw new MINBusinessException("该设备已销毁!"); } int comcosAndsal = CommonUtil.compare(costPrice, sallPrice); /* int comcosAndgam = CommonUtil.compare(costPrice, gamePrice); int comgamAndsal = CommonUtil.compare(gamePrice, sallPrice);*/ /* int comcosAndpro = CommonUtil.compare(costPrice, promottonPrice);*/ int comproAndsal = CommonUtil.compare(promottonPrice, sallPrice); int comnumAndper = CommonUtil.compare(numbers, perNum); if (comcosAndsal == 1 || comcosAndsal == 0) { throw new MINBusinessException("成本价不能大于或等于售货价!"); } /* if (comcosAndgam == 1 || comcosAndgam == 0) { throw new MINBusinessException("成本价不能大于或等于游戏价!"); } if (comgamAndsal == 1 || comgamAndsal == 0) { throw new MINBusinessException("游戏价不能大于或等于售货价!"); }*/ /*if (comcosAndpro == 1 || comcosAndpro == 0) { throw new MINBusinessException("成本价不能大于或等于促销价!"); }*/ if (comproAndsal == 1 || comproAndsal == 0) { throw new MINBusinessException("促销价不能大于或等于售货价!"); } if (comnumAndper == 1) { throw new MINBusinessException("商品余量不能大于货道容量!"); } //校验商品是否正常 // VmProductInf pro = Service.lookup(IMINDataBaseService.class) // .getMybatisMapper(VmProductInfMapper.class) // .selectByPrimaryKey(proId); // if(pro == null||pro.getState().equals("2")) { // throw new BusinessCodeException("JINM0123");//商品信息异常 // } //设备新增商品 String id = Service.lookup(IPublicService.class).getSequence("VM_PROEQUREL_ID"); VmProEquRel proEquRel = new VmProEquRel(); proEquRel.setId(id); //设备商品关联表id proEquRel.setProductId(proId); //商品id proEquRel.setEquipmentId(equId); //设备id VmProEquRelExample example = new VmProEquRelExample(); if (CommonUtil.isEmpty(aisle)) { example.createCriteria().andChannelEqualTo(channel) .andEquipmentIdEqualTo(equId) .andAisleEqualTo(perRow.concat(perLine)) .andExeitStateEqualTo("00"); List list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByExample(example); if (list.size() != 0) { throw new MINBusinessException("该设备默认货道指令已被使用!"); } proEquRel.setAisle(perRow.concat(perLine)); //货道指令 } else { example.createCriteria().andChannelEqualTo(channel) .andEquipmentIdEqualTo(equId) .andAisleEqualTo(aisle) .andExeitStateEqualTo("00"); List list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByExample(example); if (list.size() != 0) { throw new MINBusinessException("该设备货道指令已使用!"); } proEquRel.setAisle(aisle); //货道指令 } proEquRel.setCargoWayRow(perRow); //货道层 proEquRel.setCargoWayLine(perLine); //货道列 proEquRel.setCargoWayNums(perNum); //货道容量 proEquRel.setProductNums(numbers); //商品余量 proEquRel.setSallPrice(sallPrice); //售货价 if (!CommonUtil.isEmpty(gamePrice)) { proEquRel.setGamePrice(gamePrice); //游戏价 }else { proEquRel.setGamePrice("0"); } proEquRel.setCostPrice(costPrice); //成本价 proEquRel.setIsPromotion(isPromotton); //是否促销 if (!CommonUtil.isEmpty(promottonPrice)) { proEquRel.setPromotionPrice(promottonPrice); //促销价 }else { proEquRel.setPromotionPrice("0"); } /* proEquRel.setIsFragile(isFragile); //是否易碎 */ proEquRel.setUserId(uId); //商户id proEquRel.setRemarks(perRemarks); //备注 proEquRel.setGameType(type); //游戏类型 proEquRel.setChannel(channel); //渠道 proEquRel.setCreateUser(uId); //创建人 proEquRel.setCreateTime(dateTime); //创建时间 proEquRel.setModifyUser(uId); //最后修改人 proEquRel.setModifyTime(dateTime); //最后修改时间 proEquRel.setExeitState("00"); //状态 00正常 if (!CommonUtil.isEmpty(drawAmount)) { proEquRel.setDrawAmount(drawAmount); } Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .insertSelective(proEquRel); return res; } /** * 修改设备商品 * * @param perId 设备商品关联id * @param perRow 货道层 * @param perLine 货道列 * @param perNum 货道容量 * @param numbers 商品余量 * @param sallPrice 售货价 * @param gamePrice 游戏价 * @param costPrice 成本价 * @param isPromotton 是否促销 * @param promottonPrice 促销价 * @param isFragile 是否易碎 * @param perRemarks 备注 * @param proId 商品id * @param equId 设备id * @param perState 状态 * @param session * @return * @throws MINBusinessException */ @MINAction(value = EDIT_PROEQUREL) public MINActionResult editProEquRel( @MINParam(key = "perId") String perId, @MINParam(key = "aisle") String aisle, @MINParam(key = "perRow") String perRow, @MINParam(key = "perLine") String perLine, @MINParam(key = "perNum") String perNum, @MINParam(key = "numbers") String numbers, @MINParam(key = "sallPrice") String sallPrice, @MINParam(key = "gamePrice") String gamePrice, @MINParam(key = "costPrice") String costPrice, @MINParam(key = "type") String type, @MINParam(key = "isPromotton") String isPromotton, @MINParam(key = "promottonPrice") String promottonPrice, @MINParam(key = "isFragile") String isFragile, @MINParam(key = "perRemarks") String perRemarks, @MINParam(key = "proId") String proId, @MINParam(key = "equId") String equId, @MINParam(key = "perState") String perState, @MINParam(key = "luck") String luck, @MINParam(key = "accumulatedAmount") String accumulatedAmount, @MINParam(key = "drawAmount") String drawAmount, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); //当前时间 String dateTime = DateUtil.getCurrentDateTimeString(); User user = session.getUser(); //操作员id String uId = user.getId(); //渠道 String channel = user.getChannel(); //校验设备是否正常 VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByPrimaryKey(equId); if (equipmentInf == null) { throw new MINBusinessException("该设备不存在!"); } else if (equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)) { throw new MINBusinessException("该设备已销毁!"); } int comcosAndsal = CommonUtil.compare(costPrice, sallPrice); /* int comcosAndgam = CommonUtil.compare(costPrice, gamePrice); int comgamAndsal = CommonUtil.compare(gamePrice, sallPrice);*/ // int comcosAndpro = CommonUtil.compare(costPrice, promottonPrice); int comproAndsal = CommonUtil.compare(promottonPrice, sallPrice); int comnumAndper = CommonUtil.compare(numbers, perNum); if (comcosAndsal == 1 || comcosAndsal == 0) { throw new MINBusinessException("成本价不能大于或等于售货价!"); } /*if (comcosAndgam == 1 || comcosAndgam == 0) { throw new MINBusinessException("成本价不能大于或等于游戏价!"); } if (comgamAndsal == 1 || comgamAndsal == 0) { throw new MINBusinessException("游戏价不能大于或等于售货价!"); }*/ // if (comcosAndpro == 1 || comcosAndpro == 0) { // throw new MINBusinessException("成本价不能大于或等于促销价!"); // } if (comproAndsal == 1 || comproAndsal == 0) { throw new MINBusinessException("促销价不能大于或等于售货价!"); } if (comnumAndper == 1) { throw new MINBusinessException("商品余量不能大于货道容量!"); } //校验商品是否正常 // VmProductInf pro = Service.lookup(IMINDataBaseService.class) // .getMybatisMapper(VmProductInfMapper.class) // .selectByPrimaryKey(proId); VmProEquRel proEquRel = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByPrimaryKey(perId); // if(pro == null||pro.getState().equals("2")||proEquRel == null||proEquRel.getExeitState().equals("2")) { // throw new BusinessCodeException("JINM0123");//商品信息异常 // } //修改设备新增商品 if (!CommonUtil.isEmpty(proId)) { proEquRel.setProductId(proId); //商品id } if (!CommonUtil.isEmpty(equId)) { proEquRel.setEquipmentId(equId); //设备id } if (!CommonUtil.isEmpty(aisle)) { VmProEquRelExample example = new VmProEquRelExample(); example.createCriteria().andChannelEqualTo(channel) .andEquipmentIdEqualTo(equId) .andAisleEqualTo(aisle) .andExeitStateEqualTo(Constant.PROEQUREL_STT_00) .andIdNotEqualTo(perId); List list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByExample(example); if (list.size() != 0) { throw new MINBusinessException("该设备货道指令已使用!"); } proEquRel.setAisle(aisle); //货道指令 } if (!CommonUtil.isEmpty(perRow)) { proEquRel.setCargoWayRow(perRow); //货道层 } if (!CommonUtil.isEmpty(perLine)) { proEquRel.setCargoWayLine(perLine); //货道列 } if (!CommonUtil.isEmpty(perNum)) { proEquRel.setCargoWayNums(perNum); //货道容量 } if (!CommonUtil.isEmpty(numbers)) { proEquRel.setProductNums(numbers); //商品余量 } if (!CommonUtil.isEmpty(sallPrice)) { proEquRel.setSallPrice(sallPrice); //售货价 } if (!CommonUtil.isEmpty(gamePrice)) { proEquRel.setGamePrice(gamePrice); //游戏价 }else{ proEquRel.setGamePrice("0"); } if (!CommonUtil.isEmpty(costPrice)) { proEquRel.setCostPrice(costPrice); //成本价 } if (!CommonUtil.isEmpty(isPromotton)) { proEquRel.setIsPromotion(isPromotton); //是否促销 } if (!CommonUtil.isEmpty(promottonPrice)) { proEquRel.setPromotionPrice(promottonPrice); //促销价 }else { proEquRel.setPromotionPrice("0"); } /*if(!CommonUtil.isEmpty(isFragile)){ proEquRel.setIsFragile(isFragile); //是否易碎 }*/ if (!CommonUtil.isEmpty(perRemarks)) { proEquRel.setRemarks(perRemarks); //备注 } proEquRel.setGameType(type); //游戏类型 proEquRel.setModifyUser(uId); //最后修改人 proEquRel.setModifyTime(dateTime); //最后修改时间 if (!CommonUtil.isEmpty(perState)) { proEquRel.setExeitState(perState); //状态 } if (!CommonUtil.isEmpty(drawAmount)) { proEquRel.setDrawAmount(drawAmount); } proEquRel.setAccumulatedAmount("0"); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .updateByPrimaryKeySelective(proEquRel); return res; } /** * 查询设备中商品 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = QUERY_PROEQU) public MINActionResult queryProEqu( @MINParam(key = "equId") String equId, @MINParam(key = "perId") String perId, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); User user = session.getUser(); //渠道 String channel = user.getChannel(); // 查询条件 Map map = new HashMap(); map.put("channel", "V01"); map.put("equId", equId); map.put("perId", perId); List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(MachineManageMapper.class) .queryProEquRel(map); //格式化时间和状态 list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime"); list = new MINCopyFormat("{perState:'sttDesc',isPromotton:'isPromottonDesc',isFragile:'isFragileDesc'}").format(list); list = Service.lookup(IFormatService.class).formatEnum(list, "{sttDesc:'PROEQUREL_STATE',isPromottonDesc:'IS_PROMOTION',isFragileDesc:'IS_FRAGILE'}"); //传递数据 res.set(IMINBusinessConstant.F_PAGING_LAY, list); return res; } /** * 删除货道 * * @param equId 设备id * @param perState 状态 * @param session * @return * @throws MINBusinessException */ @MINAction(value = DEL_EQUPRO) public MINActionResult delEquPro( @MINParam(key = "equId") String equId, @MINParam(key = "perRow") String perRow, @MINParam(key = "perLine") String perLine, @MINParam(key = "perState") String perState, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); //当前时间 String dateTime = DateUtil.getCurrentDateTimeString(); User user = session.getUser(); //操作员id String uId = user.getId(); //渠道 String channel = user.getChannel(); //校验设备是否正常 VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByPrimaryKey(equId); if (equipmentInf == null) { throw new MINBusinessException("该设备不存在!"); } else if (equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)) { throw new MINBusinessException("该设备已销毁!"); } VmProEquRelExample equRelExample = new VmProEquRelExample(); equRelExample.createCriteria().andEquipmentIdEqualTo(equId) .andCargoWayRowEqualTo(perRow) .andCargoWayLineEqualTo(perLine) .andChannelEqualTo(channel) .andExeitStateNotEqualTo(Constant.PROEQUREL_STT_02); List list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByExample(equRelExample); if (list.size() != 0) { throw new MINBusinessException("此货道无法删除!"); } //删除货道 String id = Service.lookup(IPublicService.class).getSequence("VM_PROEQUREL_ID"); VmProEquRel proEquRel = new VmProEquRel(); proEquRel.setId(id); //设备商品关联表id proEquRel.setEquipmentId(equId); //设备id proEquRel.setCargoWayRow(perRow); //货道层 proEquRel.setCargoWayLine(perLine); //货道列 proEquRel.setUserId(uId); //商户id proEquRel.setRemarks("货道删除"); //备注 proEquRel.setChannel(channel); //渠道 proEquRel.setCreateUser(uId); //创建人 proEquRel.setCreateTime(dateTime); //创建时间 proEquRel.setModifyUser(uId); //最后修改人 proEquRel.setModifyTime(dateTime); //最后修改时间 proEquRel.setExeitState(Constant.PROEQUREL_STT_01); //状态 01货道删除 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .insertSelective(proEquRel); return res; } /** * 删除 * * @param perId 设备商品关联id * @param perState 状态 * @param session * @return * @throws MINBusinessException */ @MINAction(value = DEL_PROEQU) public MINActionResult delProEqu( @MINParam(key = "perId") String perId, @MINParam(key = "perState") String perState, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); //当前时间 String dateTime = DateUtil.getCurrentDateTimeString(); User user = session.getUser(); //操作员id String uId = user.getId(); //渠道 // String channel = user.getChannel(); //校验设备是否正常 /*VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByPrimaryKey(equId); if(equipmentInf == null){ throw new MINBusinessException("该设备不存在!"); }else if(equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)){ throw new MINBusinessException("该设备已销毁!"); } */ VmProEquRel proEquRel = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByPrimaryKey(perId); //删除 proEquRel.setId(perId); proEquRel.setExeitState(Constant.PROEQUREL_STT_02); //状态 proEquRel.setModifyUser(uId); //最后修改人 proEquRel.setModifyTime(dateTime); //最后修改时间 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .updateByPrimaryKeySelective(proEquRel); return res; } /** * 查询设备列表 * * @param equName 设备名称 * @param equState 状态 * @param session * @return * @throws MINBusinessException */ @MINAction(value = QUERY_EQUIPMENT_LINE) public MINActionResult queryEquipmentLine( @MINParam(key = "equName") String equName, @MINParam(key = "machineNo") String machineNo, @MINParam(key = "temId") String temId, @MINParam(key = "userName") String userName, @MINParam(key = "dates") String dates, @MINParam(key = "equState") String equState, @MINParam(key = "machineNomax") String machineNomax, @MINParam(key = "machineNomin") String machineNomin, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "10") int limit, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); MINRowBounds rows = new MINRowBounds(page, limit); User user = session.getUser(); //操作员id String uId = user.getId(); //渠道 String channel = user.getChannel(); // 查询条件 Map map = new HashMap(); map.put("channel", "V01"); map.put("equName", equName); map.put("equState", equState); map.put("temId", temId); map.put("userName", userName); map.put("dates", dates); map.put("machineNo", machineNo); map.put("machineNomax", machineNomax); map.put("machineNomin", machineNomin); // if(user.getRoleId().equals("10000002")){ // map.put("userId", uId); // } if (user.getIdentity().equals("00")) { map.put("userId", uId); } else if (user.getIdentity().equals("91")) { map.put("agentId", uId); } List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(MachineManageMapper.class) .queryEquipment(map, rows); //格式化时间和状态 list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime"); list = new MINCopyFormat("{equState:'sttDesc',type:'typeDesc'}").format(list); list = Service.lookup(IFormatService.class).formatEnum(list, "{sttDesc:'EQUIPMENT_STATE','typeDesc':'GAME_TYPE'}"); //传递数据 res.set(IMINBusinessConstant.F_PAGING_LAY, list); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows()); return res; } /** * 多选设备复制商品 * * @param equId 设备id * @param copyEquId 复制设备id * @param session * @return * @throws MINBusinessException */ @MINAction(value = ADD_PROEQURELALL_COPY, transaction = IMINTransactionEnum.CMT) public MINActionResult addProEquRelAllCopy( @MINParam(key = "equId") String equId, @MINParam(key = "copyEquId") String copyEquId, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); if (equId.indexOf(copyEquId) != -1) { throw new MINBusinessException("不能选择相同设备!"); } String[] equIdArr = equId.split(","); for (int i = 0; i < equIdArr.length; i++) { //当前时间 String dateTime = DateUtil.getCurrentDateTimeString(); User user = session.getUser(); //操作员id String userId = user.getId(); //渠道 String channel = "V01"; //校验设备是否正常 VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByPrimaryKey(equIdArr[i]); if (equipmentInf == null) { throw new MINBusinessException("该设备不存在!"); } else if (equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)) { throw new MINBusinessException("该设备已销毁!"); } //查询设备中原有的商品 VmProEquRelExample proEquRelExample = new VmProEquRelExample(); proEquRelExample.createCriteria().andEquipmentIdEqualTo(equIdArr[i]) .andChannelEqualTo(channel) .andExeitStateEqualTo(Constant.PROEQUREL_STT_00); List list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByExample(proEquRelExample); for (int j = 0; i < list.size(); j++) { VmProEquRel equRel = list.get(j); //设备新增商品 equRel.setExeitState(Constant.PROEQUREL_STT_02); //状态 equRel.setModifyUser(userId); //最后修改人 equRel.setModifyTime(dateTime); //最后修改时间 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .updateByPrimaryKeySelective(equRel); } //查询设备中的商品 VmProEquRelExample proEquRelExample2 = new VmProEquRelExample(); proEquRelExample2.createCriteria().andEquipmentIdEqualTo(copyEquId) .andChannelEqualTo(channel) .andExeitStateEqualTo(Constant.PROEQUREL_STT_00); List list2 = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByExample(proEquRelExample2); for (int j = 0; j < list2.size(); j++) { VmProEquRel equRel2 = list2.get(j); //设备新增商品 String id = Service.lookup(IPublicService.class).getSequence("VM_PROEQUREL_ID"); equRel2.setId(id); //设备商品关联id equRel2.setEquipmentId(equIdArr[i]); //设备id equRel2.setCreateUser(userId); //创建人 equRel2.setCreateTime(dateTime); //创建时间 equRel2.setModifyUser(userId); //最后修改人 equRel2.setModifyTime(dateTime); //最后修改时间 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .insertSelective(equRel2); } } return res; } /** * 编辑设备 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = MODIFY_PRODUCT_INF, transaction = IMINTransactionEnum.CMT) public MINActionResult modifyProductInf( @MINParam(key = "id") String id, @MINParam(key = "name") String name, @MINParam(key = "ioiServicePrivider") String ioiServicePrivider, @MINParam(key = "ioiCardNumber") String ioiCardNumber, @MINParam(key = "address") String address, @MINParam(key = "versionType") String versionType, @MINParam(key = "equType") String equType, @MINParam(key = "wcAccount") String wcAccount, @MINParam(key = "zfbAccount") String zfbAccount, @MINParam(key = "charge") String charge, @MINParam(key = "payeeNo") String payeeNo, @MINParam(key = "creditChannel") String creditChannel, @MINParam(key = "payment") String payment, @MINParam(key = "paymentType") String paymentType, @MINParam(key = "exchangeRate") String exchangeRate, @MINParam(key = "supportBalance") String supportBalance, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); //获取当前时间 String nowTime = DateUtil.getCurrentDateTimeString(); // 获取操作员信息 User user = session.getUser(); VmEquipmentInf pro = new VmEquipmentInf(); pro.setId(id); if (CommonUtil.isEmpty(name)){ pro.setName("无人售货机"); }else{ pro.setName(name); } pro.setIotCardNumber(ioiCardNumber); pro.setIotServiceProvider(ioiServicePrivider); pro.setModifyUser(user.getId()); pro.setModifyTime(nowTime); pro.setAddress(address); if(!CommonUtil.isEmpty(equType)){ pro.setEquType(equType); } pro.setWcAccount(wcAccount); pro.setZfbAccount(zfbAccount); pro.setCharge(charge); pro.setPayeeNo(payeeNo); pro.setCreditChannel(creditChannel); pro.setPayment(payment); pro.setVersionType(versionType); pro.setPaymentType(paymentType); pro.setExchangeRate(exchangeRate); pro.setSupportBalance(supportBalance); pro.setModifyUser(user.getId()); pro.setModifyTime(nowTime); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .updateByPrimaryKeySelective(pro); /*// 记录操作日志 String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id; Service.lookup(ILogService.class).logging(session, logInfo);*/ return res; } /** * 开启/关闭音乐 * * @param id 机器id * @return * @throws Exception */ @MINAction(value = CLOSE_SONG) public MINActionResult closeSong( @MINParam(key = "id") String id, @MINParam(key = "status") String status, MINSession session) throws Exception { MINActionResult res = new MINActionResult(); User user = session.getUser(); if (CommonUtil.isEmpty(id)){ throw new MINBusinessException("机器id上送为空!"); } //校验设备是否正常 VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByPrimaryKey(id); if (equipmentInf == null) { throw new MINBusinessException("该设备不存在!"); } else if (equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)) { throw new MINBusinessException("该设备已销毁!"); } VmEquipmentInf pro = new VmEquipmentInf(); pro.setId(id); pro.setSongStatus(status);//关闭 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .updateByPrimaryKeySelective(pro); return res; } /** * 一键补货 * @param equId 设备id * @param session * @return * @throws MINBusinessException */ @MINAction(value = ADD_PROEQUREL_NUM, transaction = IMINTransactionEnum.CMT) public MINActionResult addProEquRelNum( @MINParam(key = "equId") String equId, @MINParam(key = "proNum") String proNum, @MINParam(key = "proState") String proState, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); //当前时间 String dateTime = DateUtil.getCurrentDateTimeString(); User user = session.getUser(); //操作员id String userId = user.getId(); //渠道 String channel = user.getChannel(); //校验设备是否正常 VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByPrimaryKey(equId); if(equipmentInf == null){ throw new MINBusinessException("该设备不存在!"); }else if(equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)){ throw new MINBusinessException("该设备已销毁!"); } //查询设备中的商品 VmProEquRelExample proEquRelExample = new VmProEquRelExample(); proEquRelExample.createCriteria().andEquipmentIdEqualTo(equId) .andChannelEqualTo("V01") .andExeitStateEqualTo(Constant.PROEQUREL_STT_00); List list2 = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByExample(proEquRelExample); for (int i = 0; i < list2.size(); i++) { VmProEquRel equRel = list2.get(i); if(proState.equals("222")) { equRel.setProductNums(equRel.getCargoWayNums()); //商品余量修改为货道容量 }else{ equRel.setProductNums(proNum); } equRel.setModifyUser(userId); //最后修改人 equRel.setModifyTime(dateTime); //最后修改时间 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .updateByPrimaryKeySelective(equRel); } return res; } /** * 一键设置商品价格 * @param equId 设备id * @param sallPrice 售货价 * @param gamePrice 游戏价 * @param costPrice 成本价 * @param type 游戏类型 * @param isPromotton 是否促销 * @param promottonPrice 促销价 * @param session * @return * @throws MINBusinessException */ @MINAction(value = EDIT_PROEQUREL_PRICE, transaction = IMINTransactionEnum.CMT) public MINActionResult editProEquRelPrice( @MINParam(key = "equId") String equId, @MINParam(key = "sallPrice") String sallPrice, @MINParam(key = "gamePrice") String gamePrice, @MINParam(key = "costPrice") String costPrice, @MINParam(key = "type") String type, @MINParam(key = "isPromotton") String isPromotton, @MINParam(key = "promottonPrice") String promottonPrice, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); //当前时间 String dateTime = DateUtil.getCurrentDateTimeString(); User user = session.getUser(); //操作员id String userId = user.getId(); //渠道 String channel = user.getChannel(); //校验设备是否正常 VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByPrimaryKey(equId); if(equipmentInf == null){ throw new MINBusinessException("该设备不存在!"); }else if(equipmentInf.getState().equals(Constant.EQUIPMENT_STT_03)){ throw new MINBusinessException("该设备已销毁!"); } int comcosAndsal = CommonUtil.compare(costPrice, sallPrice); int comcosAndgam = CommonUtil.compare(costPrice, gamePrice); int comgamAndsal = CommonUtil.compare(gamePrice, sallPrice); // int comcosAndpro = CommonUtil.compare(costPrice, promottonPrice); int comproAndsal = CommonUtil.compare(promottonPrice, sallPrice); if (comcosAndsal == 1 || comcosAndsal == 0) { throw new MINBusinessException("成本价不能大于或等于售货价!"); } /* if (comcosAndgam == 1 || comcosAndgam == 0) { throw new MINBusinessException("成本价不能大于或等于游戏价!"); } if (comgamAndsal == 1 || comgamAndsal == 0) { throw new MINBusinessException("游戏价不能大于或等于售货价!"); }*/ // if (comcosAndpro == 1 || comcosAndpro == 0) { // throw new MINBusinessException("成本价不能大于或等于促销价!"); // } if (comproAndsal == 1 || comproAndsal == 0) { throw new MINBusinessException("促销价不能大于或等于售货价!"); } //查询设备中的商品 VmProEquRelExample proEquRelExample = new VmProEquRelExample(); proEquRelExample.createCriteria().andEquipmentIdEqualTo(equId) .andChannelEqualTo("V01") .andExeitStateEqualTo(Constant.PROEQUREL_STT_00); List list2 = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByExample(proEquRelExample); for (int i = 0; i < list2.size(); i++) { VmProEquRel equRel = list2.get(i); equRel.setSallPrice(sallPrice); //售货价 equRel.setGamePrice(gamePrice); //游戏价 equRel.setCostPrice(costPrice); //成本价 equRel.setIsPromotion(isPromotton); //是否促销 equRel.setPromotionPrice(promottonPrice); //促销价 equRel.setGameType(type); //游戏类型 equRel.setModifyUser(userId); //最后修改人 equRel.setModifyTime(dateTime); //最后修改时间 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .updateByPrimaryKeySelective(equRel); } return res; } /** * 生成包含字符串信息的二维码图片 * @param flash 是否刷新 */ @MINAction(value = CREATE_QRCODE, transaction = IMINTransactionEnum.CMT) public MINActionResult createQrCode( @MINParam(key = "flash") String flash, @MINParam(key = "equId") String equId, @MINParam(key = "equType") String equType, MINSession session)throws MINBusinessException, FileNotFoundException, WriterException, IOException { MINActionResult res = new MINActionResult(); //如果equType //获取当前用户信息 User u = session.getUser(); //获取用户id String userId = u.getBranchId(); //刷新,生成 //开发环境修改配置 String basePath = "/home/images/"+ userId+".jpg"; //与nginx配置相同 String os = System.getProperty("os.name"); if(os.toLowerCase().startsWith("win")){ System.out.println(os + " can't gunzip"); basePath = "D:/images/"+ userId+".jpg"; //与nginx配置相同 } File file = new File(basePath); //获取父目录 File fileParent = file.getParentFile(); //判断是否存在 if (!fileParent.exists()) { fileParent.mkdirs(); } //获取渠道号 String channel = "V01"; String address = Service.lookup(IPropertiesService.class) .getSystemProperties().get(channel+"_TO_MACHINE_ERWERMA").getKey();// 为nginx根路径 // 加密客户号 OutputStream outputStream = new FileOutputStream(file); String serviceUrl = Service.lookup(IPropertiesService.class) .getSystemProperties().get(channel+"_TO_MACHINE_ERWERMA").getKey(); serviceUrl = "http://".concat(serviceUrl.concat("/admin/h5/index.html?equId=").concat(equId)); //String urlString = URLEncoder.encode(, "GBK"); // 生成二维码图片到本地 try { EquCodeCreateUtil.createQrCode(outputStream,serviceUrl,900,"JPEG"); } catch (com.google.zxing.WriterException e) { // TODO Auto-generated catch block e.printStackTrace(); } outputStream.close(); // 上传图片到服务器 InputStream inputSteam = new FileInputStream(file); //String url = UpLoadFile.uploadImg(inputSteam,"jpg",channel,"00"); String ambient = Service.lookup(IPublicService.class) .getSysParValue("AMBIENT");//当前环境 InputStream inputSteams = new FileInputStream(file); FileItem fileItemb = createFileItem(file ,"itemFileName"); Map map = null; if("00".equals(ambient)){//测试 map =Service.lookup(IPublicService.class).uploadFile(fileItemb, "00", 0, true,"V01"); } if("01".equals(ambient)){//生产 map =Service.lookup(IPublicService.class).uploadFileBD(fileItemb, "00", 0, true,"V01"); } //String url = UpLoadFile.uploadImg(inputSteam,"jpg",channel,"00"); String url = String.valueOf(map.get("url")); inputSteam.close(); // 删除本地图片 file.delete(); res.set("url", url); VmEquipmentInf vmEquipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByPrimaryKey(equId); if (null != vmEquipmentInf){ vmEquipmentInf.setUrlCode(url); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .updateByPrimaryKeySelective(vmEquipmentInf); } return res; } /** * 补货 * @param perId 设备id * @param session * @return * @throws MINBusinessException */ @MINAction(value = EDIT_PROEQUREL_NUM) public MINActionResult editProEquRelNum( @MINParam(key = "perId") String perId, @MINParam(key = "proNum") String proNum, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); //当前时间 String dateTime = DateUtil.getCurrentDateTimeString(); User user = session.getUser(); //操作员id String userId = user.getId(); //渠道 // String channel = user.getChannel(); //校验设备是否正常 VmProEquRel equRel = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .selectByPrimaryKey(perId); String proNumall = equRel.getCargoWayNums(); int comcosAndsal = CommonUtil.compare(proNum, proNumall); if (comcosAndsal == 1 ) { throw new MINBusinessException("补货量不能大于货道容量!"); } if(equRel == null||equRel.getExeitState().equals(Constant.PROEQUREL_STT_02)){ throw new MINBusinessException("设备中该货物不存在!"); } equRel.setProductNums(proNum); //商品余量修改为货道容量 equRel.setModifyUser(userId); //最后修改人 equRel.setModifyTime(dateTime); //最后修改时间 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .updateByPrimaryKeySelective(equRel); return res; } /** * 添加设备 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = DELETE_EQU, transaction = IMINTransactionEnum.CMT) public MINActionResult deleteEqu( @MINParam(key = "startEquCode") String startEquCode, @MINParam(key = "endEquCode") String endEquCode, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); //获取当前时间 String nowTime = DateUtil.getCurrentDateTimeString(); // 获取操作员信息 User user = session.getUser(); if (CommonUtil.isEmpty(startEquCode)) { throw new MINBusinessException("起始解绑机台号为空"); } if (!CommonUtil.isEmpty(endEquCode)) { int code = CommonUtil.compare(startEquCode,endEquCode); if (code == 0 || code == 1){ throw new MINBusinessException("起始解绑机台号不能大于等于结束解绑机台号"); } for (int i = Integer.parseInt(startEquCode);i <= Integer.parseInt(endEquCode);i++){ VmEquipmentInfExample example = new VmEquipmentInfExample(); example.createCriteria().andMachineNoEqualTo(String.valueOf(i)); List vmEquipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByExample(example); if (vmEquipmentInf != null && vmEquipmentInf.size() > 0){ Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .deleteByPrimaryKey(vmEquipmentInf.get(0).getId()); } } }else{ VmEquipmentInfExample example = new VmEquipmentInfExample(); example.createCriteria().andMachineNoEqualTo(startEquCode); List vmEquipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByExample(example); if (vmEquipmentInf != null && vmEquipmentInf.size() > 0){ Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .deleteByPrimaryKey(vmEquipmentInf.get(0).getId()); } } /*// 记录操作日志 String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id; Service.lookup(ILogService.class).logging(session, logInfo);*/ return res; } /** * 添加设备货道 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = ADD_PRO_EQU_REL, transaction = IMINTransactionEnum.CMT) public MINActionResult addProEquRelLineRow( @MINParam(key = "line") String line, @MINParam(key = "row") String row, @MINParam(key = "equId") String equId, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); //获取当前时间 String nowTime = DateUtil.getCurrentDateTimeString(); // 获取操作员信息 User user = session.getUser(); VmProEquRelExample example = new VmProEquRelExample(); example.createCriteria().andIdEqualTo(equId).andCargoWayLineEqualTo(CommonUtil.subtract(line,"1")).andCargoWayRowEqualTo(CommonUtil.subtract(row,"1")); List List = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmProEquRelMapper.class).selectByExample(example); if (List.size()>0){ throw new MINBusinessException("货道已存在"); } String id = Service.lookup(IPublicService.class).getSequence("VM_PROEQUREL_ID"); VmProEquRel vmProEquRel = new VmProEquRel(); vmProEquRel.setId(id); vmProEquRel.setEquipmentId(equId); vmProEquRel.setCargoWayLine(CommonUtil.subtract(line,"1")); vmProEquRel.setCargoWayRow(CommonUtil.subtract(row,"1")); vmProEquRel.setExeitState("00"); vmProEquRel.setCreateTime(nowTime); vmProEquRel.setCreateUser(user.getId()); Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmProEquRelMapper.class).insertSelective(vmProEquRel); /*// 记录操作日志 String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id; Service.lookup(ILogService.class).logging(session, logInfo);*/ return res; } /** * 查询设备中商品 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = QUERY_FUNCTION) public MINActionResult queryFunction( @MINParam(key = "branchId") String branchId, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); User user = session.getUser(); //渠道 String channel = user.getChannel(); // 查询条件 Map map = new HashMap(); map.put("branchId", user.getBranchId()); List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(MachineManageMapper.class) .queryFunction(map); //传递数据 res.set(IMINBusinessConstant.F_PAGING_LAY, list); return res; } /** * 查询设备中商品 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = QUERY_PROEQURELPAGE) public MINActionResult queryProEquRelPage( @MINParam(key = "equId") String equId, @MINParam(key = "proName") String proName, @MINParam(key = "gameType") String gameType, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "10") int limit, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); MINRowBounds rows = new MINRowBounds(page, limit); User user = session.getUser(); //渠道 String channel = user.getChannel(); // 查询条件 Map map = new HashMap(); map.put("channel", "V01"); map.put("equId", equId); if(!Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(user.getBranchId())){ map.put("branchId", user.getBranchId()); } map.put("gameType", "02"); map.put("proName", proName); List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(MachineManageMapper.class) .queryProEquRelPage(map,rows); //格式化时间和状态 list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime", "modifyTime"); list = new MINCopyFormat("{perState:'sttDesc',isPromotton:'isPromottonDesc',isFragile:'isFragileDesc',type:'typeDesc'}").format(list); list = Service.lookup(IFormatService.class).formatEnum(list, "{sttDesc:'PROEQUREL_STATE',isPromottonDesc:'IS_PROMOTION',typeDesc:'GAME_SETUP_TYPE'}"); //传递数据 res.set(IMINBusinessConstant.F_PAGING_LAY, list); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows()); return res; } /** * 清空累计金额 * @param perId * @param session * @return * @throws MINBusinessException */ @MINAction(value = EMPTY_PROEQUREL) public MINActionResult emptyProEquRel( @MINParam(key = "perId") String perId, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); VmProEquRel proEquRel = new VmProEquRel(); if(CommonUtil.isEmpty(perId)){ throw new MINBusinessException("数据异常!"); } proEquRel.setId(perId); proEquRel.setAccumulatedAmount("0"); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmProEquRelMapper.class) .updateByPrimaryKeySelective(proEquRel); String logInfo = "清空累计金额:" + perId; Service.lookup(ILogService.class).logging(session, logInfo); return res; } /** * 收款商户号信息查询 * @param session * @param accountName 商户名称 * @param accountId 商户号 * @param type 商户类型 * @param page * @param limit * @return * @throws MINBusinessException */ @MINAction(value = TENCENTMANAGE_QUERY) public MINActionResult businessNumManageQuery(MINSession session, @MINParam(key = "branchId") String branchId, @MINParam(key = "accountName") String accountName, @MINParam(key = "accountId") String accountId, @MINParam(key = "type") String type, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "10") int limit) throws MINBusinessException { MINActionResult res = new MINActionResult(); // 查询当前角色编号 User u = session.getUser(); branchId = u.getBranchId(); MINRowBounds rows = new MINRowBounds(page, limit); VmHlAccountExample vmHlAccountExample = new VmHlAccountExample(); VmHlAccountExample.Criteria createCriteria = vmHlAccountExample.createCriteria(); if(!StringUtils.isNullOrEmpty(accountName)){ createCriteria.andNameLike("%"+accountName+"%"); } if(!StringUtils.isNullOrEmpty(type)){ createCriteria.andTypeEqualTo(type); } if(Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(u.getBranchId())){ if(!StringUtils.isNullOrEmpty(accountId)){ createCriteria.andUsridEqualTo(accountId); } }else{ createCriteria.andUsridEqualTo(u.getBranchId()); } createCriteria.andStateEqualTo("00"); List businessNumList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmHlAccountMapper.class).selectByExample(vmHlAccountExample,rows); businessNumList = new MINCopyFormat("{type:'typeDesc'}").format(businessNumList); businessNumList = Service.lookup(IFormatService.class).formatEnum(businessNumList, "{typeDesc:'BUSINESSNUM_TYPE'}"); businessNumList = Service.lookup(IFormatService.class).formatDateTime(businessNumList, "createTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, businessNumList); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows()); return res; } /** * 商户号信息查询 * @param session * @param accountName 商户名称 * @param accountId 商户号 * @param page * @param limit * @return * @throws MINBusinessException */ @MINAction(value = QUERY_BRANCH) public MINActionResult queryBranch(MINSession session, @MINParam(key = "accountName") String accountName, @MINParam(key = "accountId") String accountId, @MINParam(key = "type") String type, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "10") int limit) throws MINBusinessException { MINActionResult res = new MINActionResult(); // 查询当前角色编号 User u = session.getUser(); String branchId = u.getBranchId(); MINRowBounds rows = new MINRowBounds(page, limit); ImBranchExample imBranchExample = new ImBranchExample(); ImBranchExample.Criteria createCriteria = imBranchExample.createCriteria(); if(!StringUtils.isNullOrEmpty(accountName)){ createCriteria.andNameLike("%"+accountName+"%"); } if(!branchId.equals(Constant.ADMINISTRATION_SYSTEM_NUMBER)){ createCriteria.andParentidEqualTo(branchId); } if(!StringUtils.isNullOrEmpty(accountId)){ createCriteria.andIdEqualTo(accountId); } List branchList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(ImBranchMapper.class).selectByExample(imBranchExample,rows); branchList = Service.lookup(IFormatService.class).formatDateTime(branchList, "createTime"); res.set(IMINBusinessConstant.F_PAGING_LAY, branchList); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows()); return res; } /** * 添加设备 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = BIND_BRANCH, transaction = IMINTransactionEnum.CMT) public MINActionResult bindBranch( @MINParam(key = "equId") String equId, @MINParam(key = "branchId") String branchId, MINSession session) throws MINBusinessException, IOException { MINActionResult res = new MINActionResult(); //获取当前时间 String nowTime = DateUtil.getCurrentDateTimeString(); // 获取操作员信息 User user = session.getUser(); VmEquipmentInf vmEquipmentInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .selectByPrimaryKey(equId); if (null == vmEquipmentInf) { throw new MINBusinessException("机器不存在"); } vmEquipmentInf.setBranchid(branchId); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmEquipmentInfMapper.class) .updateByPrimaryKeySelective(vmEquipmentInf); /*// 记录操作日志 String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id; Service.lookup(ILogService.class).logging(session, logInfo);*/ return res; } /* 创建FileItem */ private FileItem createFileItem(File file, String fieldName) { FileItemFactory factory = new DiskFileItemFactory(16, null); FileItem item = factory.createItem(fieldName, "text/plain", true, file.getName()); int bytesRead = 0; byte[] buffer = new byte[8192]; try { FileInputStream fis = new FileInputStream(file); OutputStream os = item.getOutputStream(); while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) { os.write(buffer, 0, bytesRead); } os.close(); fis.close(); } catch (IOException e) { e.printStackTrace(); } return item; } }