IndexController.java 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369
  1. package com.szwl.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  6. import com.fasterxml.jackson.core.JsonProcessingException;
  7. import com.fasterxml.jackson.databind.JsonNode;
  8. import com.fasterxml.jackson.databind.ObjectMapper;
  9. import com.google.gson.Gson;
  10. import com.qiniu.common.QiniuException;
  11. import com.qiniu.http.Response;
  12. import com.qiniu.storage.Configuration;
  13. import com.qiniu.storage.Region;
  14. import com.qiniu.storage.UploadManager;
  15. import com.qiniu.storage.model.DefaultPutRet;
  16. import com.qiniu.util.Auth;
  17. import com.szwl.constant.ConfigConsts;
  18. import com.szwl.constant.ResponseCodesEnum;
  19. import com.szwl.model.bean.*;
  20. import com.szwl.model.bo.JsonUtils;
  21. import com.szwl.model.bo.R;
  22. import com.szwl.model.bo.ResponseModel;
  23. import com.szwl.model.entity.*;
  24. import com.szwl.model.utils.AdminUtils;
  25. import com.szwl.model.utils.HttpClientSslUtils;
  26. import com.szwl.model.utils.PushUtils;
  27. import com.szwl.model.utils.YunPianSms;
  28. import com.szwl.service.*;
  29. import com.szwl.service.es.EsTEquipmentService;
  30. import com.szwl.util.IDGenerator;
  31. import com.szwl.util.WhoIsUtil;
  32. import io.swagger.annotations.Api;
  33. import io.swagger.annotations.ApiOperation;
  34. import org.apache.commons.io.IOUtils;
  35. import org.apache.commons.lang.StringUtils;
  36. import org.springframework.amqp.core.AmqpAdmin;
  37. import org.springframework.amqp.core.Binding;
  38. import org.springframework.amqp.core.Queue;
  39. import org.springframework.beans.factory.annotation.Autowired;
  40. import org.springframework.web.bind.annotation.*;
  41. import javax.annotation.Resource;
  42. import javax.servlet.ServletInputStream;
  43. import javax.servlet.http.HttpServletRequest;
  44. import javax.servlet.http.HttpServletResponse;
  45. import java.io.*;
  46. import java.math.BigDecimal;
  47. import java.math.RoundingMode;
  48. import java.text.ParseException;
  49. import java.text.SimpleDateFormat;
  50. import java.util.*;
  51. import static com.szwl.util.geoCoderUtil.getLocByLonLatVer;
  52. @Api(value = "/indexController", tags = {"设备信息上传接口"})
  53. @RestController
  54. @RequestMapping("/api/app_equipment/index")
  55. public class IndexController {
  56. @Autowired
  57. TAdminService adminService;
  58. @Autowired
  59. TEquipmentService equipmentService;
  60. @Autowired
  61. TEquipmentApplyService equipmentApplyService;
  62. @Autowired
  63. TProductService productService;
  64. @Autowired
  65. TProportionService proportionService;
  66. @Autowired
  67. TEquipmentDescService equipmentDescService;
  68. @Autowired
  69. EsTEquipmentService esTEquipmentService;
  70. @Autowired
  71. TParametersService parametersService;
  72. @Autowired
  73. TPriceService priceService;
  74. @Autowired
  75. TPromoCodeService promoCodeService;
  76. @Autowired
  77. TDiyFlowerService diyFlowerService;
  78. @Autowired
  79. TNameDictionaryService nameDictionaryService;
  80. @Autowired
  81. private AmqpAdmin amqpAdmin;
  82. @Resource
  83. TLocationCheckService locationCheckService;
  84. @Autowired
  85. TGoodsDataService goodsDataService;
  86. private static final String appid = "07784f5fedb508046c841b391005b7de";
  87. @ApiOperation(value = "心跳")
  88. @RequestMapping(value = "/heart.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  89. @ResponseBody
  90. public String heart(@RequestBody EquipmentVo equipmentVo) {
  91. String clientId = equipmentVo.getClientId();
  92. Date lastUpdateTime = equipmentVo.getLastUpdateTime();
  93. Double longitude = equipmentVo.getLongitude();
  94. Double latitude = equipmentVo.getLatitude();
  95. String cabinetHd = equipmentVo.getCabinetHd();
  96. String cabinetTm = equipmentVo.getCabinetTm();
  97. String furnaceSp = equipmentVo.getFurnaceSp();
  98. String furnaceTm = equipmentVo.getFurnaceTm();
  99. String gtClientId = equipmentVo.getGtClientId();
  100. String volume = equipmentVo.getVolume();
  101. Integer eqeStatus = equipmentVo.getEqeStatus();
  102. Boolean is_sleep = equipmentVo.getIs_sleep();
  103. String netWorkingMode = equipmentVo.getNetWorkingMode();
  104. String numberOne = equipmentVo.getNumberOne();
  105. String candyGeneratorTm = equipmentVo.getCandyGeneratorTm();
  106. String outsideTm = equipmentVo.getOutsideTm();
  107. String outsideHd = equipmentVo.getOutsideHd();
  108. //有记录,则进行修改
  109. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  110. query.eq(TEquipment::getClientId, clientId);
  111. TEquipment _new = equipmentService.getOne(query);
  112. if (_new != null) {
  113. _new.setNetWorkingMode(netWorkingMode);
  114. if (StringUtils.isNotEmpty(cabinetTm)) {
  115. _new.setCabinetTm(cabinetTm);
  116. }
  117. if (StringUtils.isNotEmpty(cabinetHd)) {
  118. _new.setCabinetHd(cabinetHd);
  119. }
  120. if (StringUtils.isNotEmpty(furnaceSp)) {
  121. _new.setFurnaceSp(furnaceSp);
  122. }
  123. if (StringUtils.isNotEmpty(furnaceTm)) {
  124. _new.setFurnaceTm(furnaceTm);
  125. }
  126. _new.setLastUpdateTime(lastUpdateTime);
  127. // _new.setLongitude(longitude);
  128. if (eqeStatus != null) {
  129. _new.setEqeStatus(eqeStatus);
  130. }
  131. if (is_sleep != null) {
  132. _new.setIsSleep(is_sleep);
  133. }
  134. if (!StringUtils.isEmpty(furnaceTm)) {
  135. int fur = Integer.parseInt(furnaceTm);
  136. if (_new.getEqeStatus() == 0 && fur > 150) {
  137. _new.setEqeStatus(1);
  138. }
  139. if (_new.getEqeStatus() == null && fur > 150) {
  140. _new.setEqeStatus(1);
  141. }
  142. }
  143. if (!StringUtils.isEmpty(volume)) {
  144. _new.setVolume(volume);
  145. }
  146. // _new.setLatitude(latitude);
  147. _new.setGtClientId(gtClientId);
  148. _new.setModifyDate(new Date());
  149. equipmentService.updateById(_new);
  150. TEquipmentDesc equipmentDesc = equipmentDescService.getById(_new.getId());
  151. if (StringUtils.isNotEmpty(equipmentVo.getBlueSugar())) {
  152. equipmentDesc.setBlueSugar(equipmentVo.getBlueSugar());
  153. }
  154. if (StringUtils.isNotEmpty(equipmentVo.getRedSugar())) {
  155. equipmentDesc.setRedSugar(equipmentVo.getRedSugar());
  156. }
  157. if (StringUtils.isNotEmpty(equipmentVo.getYellowSugar())) {
  158. equipmentDesc.setYellowSugar(equipmentVo.getYellowSugar());
  159. }
  160. if (StringUtils.isNotEmpty(equipmentVo.getWhiteSugar())) {
  161. equipmentDesc.setWhiteSugar(equipmentVo.getWhiteSugar());
  162. }
  163. if (StringUtils.isNotEmpty(equipmentVo.getWater())) {
  164. equipmentDesc.setWater(equipmentVo.getWater());
  165. }
  166. if (StringUtils.isNotEmpty(equipmentVo.getWasteWater())) {
  167. equipmentDesc.setWasteWater(equipmentVo.getWasteWater());
  168. }
  169. if (StringUtils.isNotEmpty(equipmentVo.getStick())) {
  170. equipmentDesc.setStick(equipmentVo.getStick());
  171. }
  172. if (equipmentVo.getCupQuantity() != null) {
  173. equipmentDesc.setCupQuantity(equipmentVo.getCupQuantity());
  174. }
  175. if (StringUtils.isNotEmpty(equipmentVo.getStirTm())) {
  176. equipmentDesc.setStirTm(equipmentVo.getStirTm());
  177. }
  178. if (StringUtils.isNotEmpty(equipmentVo.getCornGeneratorTm())) {
  179. equipmentDesc.setCornGeneratorTm(equipmentVo.getCornGeneratorTm());
  180. }
  181. if (StringUtils.isNotEmpty(numberOne)) {
  182. equipmentDesc.setNumberOne(numberOne);
  183. }
  184. if (StringUtils.isNotEmpty(candyGeneratorTm)) {
  185. equipmentDesc.setCandyGeneratorTm(candyGeneratorTm);
  186. }
  187. if (StringUtils.isNotEmpty(outsideHd)) {
  188. equipmentDesc.setOutsideHd(outsideHd);
  189. }
  190. if (StringUtils.isNotEmpty(outsideTm)) {
  191. equipmentDesc.setOutsideTm(outsideTm);
  192. }
  193. equipmentDescService.updateById(equipmentDesc);
  194. return "心跳成功";
  195. }
  196. return "心跳失败";
  197. }
  198. /**
  199. * 设备初始化申请2
  200. */
  201. @ApiOperation(value = "设备初始化申请2")
  202. @RequestMapping(value = "/initNew2.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  203. @ResponseBody
  204. public String initNew2(String clientId, String managerId, String gtClientId, String equipmentType, String ip, String longitude, String latitude) throws IOException {
  205. if (StringUtils.isEmpty(ip) || StringUtils.isEmpty(clientId)) {
  206. return "ip、clientId不能为空";
  207. }
  208. // 根据 clientId 查设备的 location,country
  209. LambdaQueryWrapper<TLocationCheck> lqw = Wrappers.lambdaQuery();
  210. lqw.eq(TLocationCheck::getClientId, clientId);
  211. TLocationCheck locationCheck = locationCheckService.getOne(lqw);
  212. if (Objects.isNull(locationCheck)) {
  213. return "生产部未录入改设备的位置信息";
  214. }
  215. // 判断ip是否属于国内,if 国内,放行
  216. double lon = Double.parseDouble(longitude);
  217. double lat = Double.parseDouble(latitude);
  218. // 经度范围在73至135之间,纬度范围在3至53之间,即国内区域
  219. // 经度:73~124,纬度17~47,经度排除韩国,纬度排除俄罗斯,海南以南
  220. if (!(lon >= 73) || !(lon <= 124) || !(lat >= 17) || !(lat <= 47)) {
  221. // 根据 ip 校验位置信息
  222. // String addr = WhoIsUtil.getLocByIp(ip);
  223. // 根据 longitude, latitude 校验位置信息
  224. String addr = null;
  225. try {
  226. addr = getLocByLonLatVer(longitude, latitude);
  227. } catch (Exception e) {
  228. throw new RuntimeException(e);
  229. }
  230. locationCheck.setIp(ip);
  231. locationCheck.setAddr(addr);
  232. locationCheckService.saveOrUpdate(locationCheck);
  233. String checkResult = locationCheckService.locCheckMsg(locationCheck, clientId, addr);
  234. if (checkResult.equals("fail")) {
  235. return "位置不匹配,请联系营销经理/售后处理";
  236. }
  237. }
  238. return this.initNew(clientId, managerId, gtClientId, equipmentType);
  239. // ObjectMapper objectMapper = new ObjectMapper();
  240. // JsonNode jsonNode = objectMapper.readTree(s);
  241. // String pro = jsonNode.get("pro").asText();
  242. // String proCode = jsonNode.get("proCode").asText();
  243. // String city = jsonNode.get("city").asText();
  244. // String cityCode = jsonNode.get("cityCode").asText();
  245. // String region = jsonNode.get("region").asText();
  246. // String regionCode = jsonNode.get("regionCode").asText();
  247. // String regionNames = jsonNode.get("regionNames").asText();
  248. // String addr = jsonNode.get("addr").asText();
  249. // String err = jsonNode.get("err").asText();
  250. // locationCheck.setPro(pro);
  251. // locationCheck.setProCode(proCode);
  252. // locationCheck.setCity(city);
  253. // locationCheck.setCityCode(cityCode);
  254. // locationCheck.setRegion(region);
  255. // locationCheck.setRegionCode(regionCode);
  256. // locationCheck.setRegionNames(regionNames);
  257. // locationCheck.setErr(err);
  258. // String location = locationCheck.getLocation();
  259. // String country = locationCheck.getCountry();
  260. // boolean containsUserInput = false;
  261. // if (StringUtils.isEmpty(location)) {
  262. // // 只需要判断 pro,city,region,addr中是否包含 country
  263. // if (StringUtils.isNotEmpty(pro) && pro.contains(country)) {
  264. // containsUserInput = true;
  265. // } else if (StringUtils.isNotEmpty(city) && city.contains(country)) {
  266. // containsUserInput = true;
  267. // } else if (StringUtils.isNotEmpty(region) && region.contains(country)) {
  268. // containsUserInput = true;
  269. // } else if (StringUtils.isNotEmpty(addr) && addr.contains(country)) {
  270. // containsUserInput = true;
  271. // }
  272. // }
  273. // 判断 pro,city,region,addr中是否包含 country 或 location
  274. // boolean containsUserInput = true;
  275. // if (StringUtils.isEmpty(location)) {
  276. // containsUserInput = addr.contains(country);
  277. // } else {
  278. // containsUserInput = addr.contains(country) || addr.contains(location);
  279. // }
  280. //
  281. // String phone = "18620242721";
  282. // String messages = "【申泽部门】设备编号:" + clientId + ",所在ip与设定位置不符,请及时查看。";
  283. // if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
  284. // YunPianSms.sendSms(appid, messages, phone);
  285. // return "位置不匹配,请联系售后或营销经理处理";
  286. // }
  287. }
  288. /**
  289. * 设备申请
  290. *
  291. * @param clientId 个推
  292. * @param managerId 管理系统id
  293. * @return
  294. */
  295. @ApiOperation(value = "设备申请")
  296. @RequestMapping(value = "/initNew.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  297. @ResponseBody
  298. public String initNew(String clientId, String managerId, String gtClientId, String equimentType) {
  299. String machineType = "0";
  300. String status = "0";
  301. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  302. query.like(TEquipment::getClientId, clientId);
  303. List<TEquipment> list = equipmentService.list(query);
  304. if (list.size() > 0) {
  305. TEquipment equipment = list.get(0);
  306. if (equipment.getAdminId() != 31) {
  307. if (!equipment.getClientId().substring(equipment.getClientId().length() - 3, equipment.getClientId().length()).equals("xxx")) {
  308. String managerId1 = equipment.getManagerId();
  309. if (!managerId.equals(managerId1)) {
  310. return "该设备未脱离";
  311. } else {
  312. return "该设备已经初始化";
  313. }
  314. }
  315. } else {
  316. status = "1";
  317. }
  318. }
  319. if (StringUtils.isEmpty(gtClientId)) {
  320. return "设备不能为空";
  321. }
  322. LambdaQueryWrapper<TEquipmentApply> query1 = Wrappers.lambdaQuery();
  323. query1.eq(TEquipmentApply::getClientId, clientId);
  324. query1.eq(TEquipmentApply::getStatusType, "1");
  325. query1.eq(TEquipmentApply::getManagerId, managerId);
  326. String dateStr = "2022-12-28 00:00:00";
  327. //获得SimpleDateFormat类,我们转换为yyyy-MM-dd的时间格式
  328. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  329. try {
  330. //使用SimpleDateFormat的parse()方法生成Date
  331. Date date = sf.parse(dateStr);
  332. query1.gt(TEquipmentApply::getCreateDate, date);
  333. } catch (ParseException e) {
  334. e.printStackTrace();
  335. }
  336. List<TEquipmentApply> list1 = equipmentApplyService.list(query1);
  337. if (list1.size() > 0) {
  338. return "重复申请";
  339. }
  340. TEquipmentApply equipmentApply = new TEquipmentApply();
  341. equipmentApply.setStatusType(1);
  342. equipmentApply.setClientId(clientId);
  343. equipmentApply.setManagerId(managerId);
  344. equipmentApply.setGtClientId(gtClientId);
  345. Long adminId = AdminUtils.decrypt(false, managerId);
  346. TAdmin admin = adminService.getById(adminId);
  347. if (admin == null) {
  348. return "找不到商家";
  349. }
  350. //所属商家
  351. String username = admin.getUsername();
  352. equipmentApply.setAdminId(adminId);
  353. equipmentApply.setAdminUserName(username);
  354. equipmentApply.setEquimentType(equimentType);
  355. // 如果是爆米花
  356. if (equimentType.equals("P30")) {
  357. machineType = "1";
  358. }
  359. // 如果是冰淇淋
  360. if (equimentType.equals("SI320")) {
  361. machineType = "2";
  362. }
  363. equipmentApply.setMachineType(machineType);
  364. equipmentApply.setCreateDate(new Date());
  365. equipmentApply.setModifyDate(new Date());
  366. equipmentApplyService.save(equipmentApply);
  367. if (status.equals("1") || String.valueOf(adminId).equals("3") || String.valueOf(adminId).equals("31") || String.valueOf(adminId).equals("506") || String.valueOf(adminId).equals("1090")) {
  368. Long id = equipmentApply.getId();
  369. agree(id);
  370. return "设备申请成功";
  371. }
  372. if (admin.getApplyStartTime() != null && admin.getApplyEndTime() != null) {
  373. Date applyStartTime = admin.getApplyStartTime();
  374. Date applyEndTime = admin.getApplyEndTime();
  375. Date now = new Date();
  376. if (now.getTime() > applyStartTime.getTime() && now.getTime() < applyEndTime.getTime()) {
  377. Long id = equipmentApply.getId();
  378. agree(id);
  379. return "设备申请成功";
  380. }
  381. }
  382. return "设备申请中,请耐心等待";
  383. }
  384. // @ApiOperation(value = "同意设备申请")
  385. // @RequestMapping(value = "/agree", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  386. // @ResponseBody
  387. private void agree(Long id) {
  388. String status = "agreed";
  389. if (null != id) {
  390. TEquipmentApply equipmentApply = equipmentApplyService.getById(id);
  391. Integer statusType = equipmentApply.getStatusType();
  392. if (statusType > 1) {
  393. equipmentApply = null;
  394. }
  395. if (equipmentApply != null) {
  396. if (!StringUtils.isEmpty(status)) {
  397. if (status.equals("agreed")) {
  398. String clientId = equipmentApply.getClientId();
  399. //判断是否设备初始化
  400. Long adminId = equipmentApply.getAdminId();
  401. String adminLevel = equipmentApply.getAdminLevel();
  402. String adminUserName = equipmentApply.getAdminUserName();
  403. String gtClientId = equipmentApply.getGtClientId();
  404. String equimentType = equipmentApply.getEquimentType();
  405. String machineType = equipmentApply.getMachineType();
  406. TAdmin admin = adminService.getById(adminId);
  407. String companyType = admin.getCompanyType(); // 公司平台
  408. String old = "";
  409. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  410. query.like(TEquipment::getClientId, clientId + "xxx");
  411. List<TEquipment> list = equipmentService.list(query);
  412. LambdaQueryWrapper<TEquipment> query0 = Wrappers.lambdaQuery();
  413. query0.eq(TEquipment::getClientId, clientId);
  414. List<TEquipment> list2 = equipmentService.list(query0);
  415. equipmentApply.setStatusType(3);
  416. if (list.size() > 0 || list2.size() > 0) {
  417. //表示设备第二次申请了:主要为了区分脱离以及初始化
  418. old = "1";
  419. //重新修改设备名称
  420. TEquipment equipment = new TEquipment();
  421. if (list2.size() > 0) {
  422. equipment = list2.get(0);
  423. } else {
  424. equipment = list.get(0);
  425. }
  426. equipment.setClientId(clientId);
  427. equipment.setGtClientId(gtClientId);
  428. equipment.setAdminId(adminId);
  429. equipment.setAdminLevel(adminLevel);
  430. equipment.setAdminUserName(adminUserName);
  431. equipment.setMachineType(machineType);
  432. equipment.setCompanyType(companyType);
  433. if (equipmentApply.getEquimentType().equals("MG320-1")) {
  434. if (!equipmentApply.getEquimentType().equals(equipment.getEquimentType()) && equipment.getEquimentType().equals("MG320")) {
  435. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  436. queryProduct.eq(TProduct::getEquipmentId, equipment.getId());
  437. List<TProduct> productList = productService.list(queryProduct);
  438. if (productList.size() == 18) {
  439. //从18种变成30种花型
  440. saveProductMG12(equipment.getId());
  441. }
  442. }
  443. equipment.setEquimentType("MG320");
  444. } else {
  445. equipment.setEquimentType(equipmentApply.getEquimentType());
  446. }
  447. // if (equipmentApply.getEquimentType().equals("MG330")) {
  448. // equipment.setEquimentType("MG330");
  449. // }
  450. // if (equipmentApply.getEquimentType().equals("P30")) {
  451. // equipment.setEquimentType(equipmentApply.getEquimentType());
  452. // }
  453. // if (equipmentApply.getEquimentType().equals("SI320")) {
  454. // equipment.setEquimentType(equipmentApply.getEquimentType());
  455. // }
  456. equipmentService.updateById(equipment);
  457. LambdaQueryWrapper<TProportion> queryProportion = Wrappers.lambdaQuery();
  458. queryProportion.eq(TProportion::getEquipmentId, equipment.getId());
  459. List<TProportion> list1 = proportionService.list(queryProportion);
  460. if (list1.size() > 0) {
  461. for (TProportion proportion : list1) {
  462. proportionService.removeById(proportion.getId());
  463. }
  464. }
  465. try {
  466. esTEquipmentService.updateDataById(equipment);
  467. } catch (Exception e) {
  468. e.printStackTrace();
  469. }
  470. if (StringUtils.isEmpty(machineType) || machineType.equals("0")) {
  471. equipmentService.sentMessage(clientId, PushUtils.buildJson("statusType", "agreed" + old).toString());
  472. PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
  473. } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("1")){
  474. equipmentService.sentMessage(clientId, PushUtils.buildJson("statusType", "agreed" + old).toString());
  475. PushUtils.push(equipmentApply.getGtClientId(), "【爆米花】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
  476. } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("2")){
  477. equipmentService.sentMessage(clientId, PushUtils.buildJson("statusType", "agreed" + old).toString());
  478. PushUtils.push(equipmentApply.getGtClientId(), "【冰淇淋】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
  479. }
  480. if (equipment.getEquimentType().equals("280")) {
  481. equipmentService.sentMessage(clientId, PushUtils.buildJson("endDate", String.valueOf(equipment.getEndDate().getTime())).toString());
  482. PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate", String.valueOf(equipment.getEndDate().getTime())).toString());
  483. }
  484. LambdaQueryWrapper<TEquipmentDesc> lqw = Wrappers.lambdaQuery();
  485. lqw.eq(TEquipmentDesc::getEquipmentId, equipment.getId());
  486. List<TEquipmentDesc> equipmentDescs = equipmentDescService.list(lqw);
  487. if (equipmentDescs.size() == 0) {
  488. TEquipmentDesc equipmentDesc = new TEquipmentDesc();
  489. equipmentDesc.setEquipmentId(equipment.getId());
  490. equipmentDescService.save(equipmentDesc);
  491. }
  492. } else {
  493. TEquipment equipment = new TEquipment();
  494. equipment.setId(IDGenerator.commonID());
  495. equipment.setCreateDate(new Date());
  496. equipment.setModifyDate(new Date());
  497. equipment.setClientId(clientId);
  498. equipment.setManagerId(equipmentApply.getManagerId());
  499. equipment.setAdminId(adminId);
  500. equipment.setAdminLevel(adminLevel);
  501. equipment.setGtClientId(gtClientId);
  502. equipment.setAdminUserName(adminUserName);
  503. equipment.setIsUsing(true);
  504. equipment.setIsNetWork(true);
  505. equipment.setGuestPwd("123456");
  506. equipment.setAdminPwd("123456");
  507. equipment.setChannel("1");
  508. equipment.setProductTotal(0);
  509. equipment.setCompanyType(companyType);
  510. //设置默认规则
  511. equipment.setTimeRuleId(Long.valueOf(1));
  512. if (equimentType.equals("MG320-1")) {
  513. equipment.setEquimentType("MG320");
  514. } else {
  515. equipment.setEquimentType(equimentType);
  516. }
  517. if (!StringUtils.isEmpty(equimentType) && equimentType.equals("MG280")) {
  518. Long monthBegin = getMonthBegin(new Date());
  519. long time = System.currentTimeMillis();
  520. if (time < monthBegin) {
  521. equipment.setEndDate(new Date(monthBegin));
  522. } else {
  523. Date date = nextMonthDate();
  524. equipment.setEndDate(date);
  525. }
  526. equipmentService.sentMessage(clientId, PushUtils.buildJson("endDate", String.valueOf(equipment.getEndDate().getTime())).toString());
  527. PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate", String.valueOf(equipment.getEndDate().getTime())).toString());
  528. }
  529. equipmentService.save(equipment);
  530. if (StringUtils.isEmpty(machineType) || machineType.equals("0")) {
  531. equipmentService.sentMessage(clientId, PushUtils.buildJson("statusType", "agreed" + old).toString());
  532. PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
  533. } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("1")){
  534. equipmentService.sentMessage(clientId, PushUtils.buildJson("statusType", "agreed" + old).toString());
  535. PushUtils.push(equipmentApply.getGtClientId(), "【爆米花】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
  536. } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("2")){
  537. equipmentService.sentMessage(clientId, PushUtils.buildJson("statusType", "agreed" + old).toString());
  538. PushUtils.push(equipmentApply.getGtClientId(), "【冰淇淋】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
  539. }
  540. LambdaQueryWrapper<TEquipment> query3 = Wrappers.lambdaQuery();
  541. query3.eq(TEquipment::getClientId, clientId);
  542. TEquipment tEquipment = equipmentService.getOne(query3);
  543. try {
  544. if (tEquipment != null) {
  545. esTEquipmentService.insertData(tEquipment);
  546. }
  547. } catch (Exception e) {
  548. e.printStackTrace();
  549. }
  550. TEquipmentDesc equipmentDesc = new TEquipmentDesc();
  551. equipmentDesc.setEquipmentId(tEquipment.getId());
  552. equipmentDescService.save(equipmentDesc);
  553. }
  554. //获取设备的id
  555. LambdaQueryWrapper<TEquipment> query1 = Wrappers.lambdaQuery();
  556. query1.eq(TEquipment::getClientId, clientId);
  557. TEquipment equipment = equipmentService.getOne(query1);
  558. Long equipmentId = equipment.getId();
  559. // 如果存在旧花型,就删除重新创建
  560. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  561. queryProduct.eq(TProduct::getEquipmentId, equipment.getId());
  562. List<TProduct> productList = productService.list(queryProduct);
  563. if (productList.size() > 0) {
  564. for (TProduct product : productList) {
  565. productService.removeById(product.getId());
  566. }
  567. }
  568. if (StringUtils.isEmpty(machineType) || machineType.equals("0")) {
  569. if (equipmentApply.getEquimentType() != null && equipmentApply.getEquimentType().equals("MG280")) {
  570. saveProductMG280(equipmentId);
  571. } else if (equipmentApply.getEquimentType() != null && equipmentApply.getEquimentType().equals("MG320-1")) {
  572. saveProductMG1(equipmentId);
  573. } else {
  574. saveProduct(equipmentId);
  575. }
  576. } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("1")){
  577. if (equimentType.equals("P30")) {
  578. saveGoodsData(equipmentId, machineType, 6);
  579. }
  580. } else if (StringUtils.isNotEmpty(machineType) && machineType.equals("2")){
  581. if (equimentType.equals("SI320")) {
  582. saveGoodsData(equipmentId, machineType, 6);
  583. }
  584. }
  585. if (String.valueOf(adminId).equals("3") || String.valueOf(adminId).equals("31") || String.valueOf(adminId).equals("506") || String.valueOf(adminId).equals("1090")) {
  586. //自动设置分销
  587. setProportion(adminId, equipmentId, clientId);
  588. }
  589. } else if (status.equals("rejected")) {
  590. equipmentApply.setStatusType(2);
  591. equipmentService.sentMessage(equipmentApply.getClientId(), PushUtils.buildJson("statusType", "rejected").toString());
  592. }
  593. equipmentApplyService.updateById(equipmentApply);
  594. }
  595. }
  596. }
  597. }
  598. private void setProportion(Long adminId, Long equipmentId, String clientId) {
  599. //先找到原账户的分销
  600. LambdaQueryWrapper<TProportion> query3 = Wrappers.lambdaQuery();
  601. query3.eq(TProportion::getAdminId, adminId);
  602. List<TProportion> list3 = proportionService.list(query3);
  603. if (list3.size() > 0) {
  604. TProportion adminProportion = list3.get(0);
  605. if (StringUtils.isEmpty(adminProportion.getClientId())) {
  606. TProportion equipmentProportion = new TProportion();
  607. equipmentProportion.setCreateDate(new Date());
  608. equipmentProportion.setModifyDate(new Date());
  609. equipmentProportion.setAdminId(adminId);
  610. equipmentProportion.setClientId(clientId);
  611. equipmentProportion.setEquipmentId(equipmentId);
  612. equipmentProportion.setAdminProportion(adminProportion.getAdminProportion());
  613. Integer type = adminProportion.getType();
  614. if (type != null) {
  615. switch (type) {
  616. case 1:
  617. equipmentProportion.setProportion(adminProportion.getAgencyProportion());
  618. equipmentProportion.setAgencyProportion(new BigDecimal("0.00"));
  619. equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
  620. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  621. equipmentProportion.setType(0);
  622. break;
  623. case 2:
  624. equipmentProportion.setProportion(adminProportion.getMerchantProportion());
  625. equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
  626. equipmentProportion.setAgencyId(adminProportion.getAgencyId());
  627. TAdmin byId = adminService.getById(adminProportion.getAgencyId());
  628. equipmentProportion.setAgencyName(byId.getUsername());
  629. equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
  630. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  631. equipmentProportion.setType(1);
  632. break;
  633. case 3:
  634. equipmentProportion.setProportion(adminProportion.getPersonageProportion());
  635. equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
  636. equipmentProportion.setAgencyId(adminProportion.getAgencyId());
  637. TAdmin byId1 = adminService.getById(adminProportion.getAgencyId());
  638. equipmentProportion.setAgencyName(byId1.getUsername());
  639. equipmentProportion.setMerchantProportion(adminProportion.getMerchantProportion());
  640. equipmentProportion.setMerchantId(adminProportion.getMerchantId());
  641. TAdmin byId2 = adminService.getById(adminProportion.getMerchantId());
  642. equipmentProportion.setMerchantName(byId2.getUsername());
  643. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  644. equipmentProportion.setType(2);
  645. break;
  646. }
  647. boolean save = proportionService.save(equipmentProportion);
  648. }
  649. }
  650. }
  651. }
  652. /**
  653. * 添加商品
  654. * @param id
  655. * @param machineType
  656. * @param number
  657. */
  658. private void saveGoodsData(Long id, String machineType, Integer number) {
  659. LambdaQueryWrapper<TGoodsData> wrapper = Wrappers.lambdaQuery();
  660. wrapper.eq(TGoodsData::getNumber, number);
  661. wrapper.eq(TGoodsData::getMachineType, machineType);
  662. TGoodsData goodsData = goodsDataService.getOne(wrapper);
  663. String goods = goodsData.getGoods();
  664. String[] str = goods.split(",");
  665. for (int i = 0; i < str.length; i++) {
  666. TProduct product = new TProduct();
  667. product.setCreateDate(new Date());
  668. product.setModifyDate(new Date());
  669. product.setEquipmentId(id);
  670. String[] split = str[i].split("-");
  671. product.setProductName(split[0]);
  672. product.setNo(split[1]);
  673. product.setRmbPrice(new BigDecimal(0.01));
  674. product.setCodePrice(new BigDecimal(0.01));
  675. productService.save(product);
  676. }
  677. }
  678. /**
  679. * 添加棉花糖产品
  680. *
  681. * @param id
  682. */
  683. private void saveProduct(Long id) {
  684. String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
  685. "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18"};
  686. for (int i = 0; i < str.length; i++) {
  687. TProduct product = new TProduct();
  688. product.setCreateDate(new Date());
  689. product.setModifyDate(new Date());
  690. product.setEquipmentId(id);
  691. String[] split = str[i].split("-");
  692. product.setProductName(split[0]);
  693. product.setNo(split[1]);
  694. product.setRmbPrice(BigDecimal.ZERO);
  695. product.setCodePrice(BigDecimal.ZERO);
  696. productService.save(product);
  697. }
  698. }
  699. private void saveProductMG280(Long id) {
  700. String[] str = {"水中芙蓉-A05", "水中芙蓉mini-A31", "烈焰红唇-A06", "烈焰红唇mini-A32", "夏日爱恋-A11", "夏日爱恋mini-A33", "冰美人-A12", "冰美人mini-A34", "彩色精灵-A17", "彩色精灵mini-A35"};
  701. for (int i = 0; i < str.length; i++) {
  702. TProduct product = new TProduct();
  703. product.setCreateDate(new Date());
  704. product.setModifyDate(new Date());
  705. product.setEquipmentId(id);
  706. String[] split = str[i].split("-");
  707. product.setProductName(split[0]);
  708. product.setNo(split[1]);
  709. product.setRmbPrice(BigDecimal.ZERO);
  710. product.setCodePrice(BigDecimal.ZERO);
  711. productService.save(product);
  712. }
  713. }
  714. private void saveProductMG1(Long id) {
  715. String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09",
  716. "心之守护-A10", "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18",
  717. "精灵蝶梦-A19", "夏日倾城-A20", "百花齐放-A21", "蜂缠蝶恋-A22", "豆蔻年华-A23", "星空幻想-A24", "坠入星空-A25", "雪花飞舞-A26", "春暖花开-A27", "花飞蝶舞-A28",
  718. "花样年华-A29", "心花怒放-A30"};
  719. for (int i = 0; i < str.length; i++) {
  720. TProduct product = new TProduct();
  721. product.setCreateDate(new Date());
  722. product.setModifyDate(new Date());
  723. product.setEquipmentId(id);
  724. String[] split = str[i].split("-");
  725. product.setProductName(split[0]);
  726. product.setNo(split[1]);
  727. product.setRmbPrice(BigDecimal.ZERO);
  728. product.setCodePrice(BigDecimal.ZERO);
  729. productService.save(product);
  730. }
  731. }
  732. private void saveProductMG12(Long id) {
  733. String[] str = {"精灵蝶梦-A19", "夏日倾城-A20", "百花齐放-A21", "蜂缠蝶恋-A22", "豆蔻年华-A23", "星空幻想-A24"
  734. , "坠入星空-A25", "雪花飞舞-A26", "春暖花开-A27", "花飞蝶舞-A28", "花样年华-A29", "心花怒放-A30"};
  735. for (int i = 0; i < str.length; i++) {
  736. TProduct product = new TProduct();
  737. product.setEquipmentId(id);
  738. product.setCreateDate(new Date());
  739. product.setModifyDate(new Date());
  740. String[] split = str[i].split("-");
  741. product.setProductName(split[0]);
  742. product.setNo(split[1]);
  743. product.setRmbPrice(BigDecimal.ZERO);
  744. product.setCodePrice(BigDecimal.ZERO);
  745. productService.save(product);
  746. }
  747. }
  748. private void saveProductMG22(Long id) {
  749. String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
  750. "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19", "蜂缠蝶恋-A22", "坠入星空-A25", "花飞蝶舞-A28"};
  751. for (int i = 0; i < str.length; i++) {
  752. TProduct product = new TProduct();
  753. product.setCreateDate(new Date());
  754. product.setModifyDate(new Date());
  755. product.setEquipmentId(id);
  756. String[] split = str[i].split("-");
  757. product.setProductName(split[0]);
  758. product.setNo(split[1]);
  759. product.setRmbPrice(BigDecimal.ZERO);
  760. product.setCodePrice(BigDecimal.ZERO);
  761. productService.save(product);
  762. }
  763. }
  764. private void saveProductMG26(Long id) {
  765. String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
  766. "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19", "蜂缠蝶恋-A22", "坠入星空-A25", "花飞蝶舞-A28",
  767. "夏日倾城-A20", "雪花飞舞-A26", "豆蔻年华-A23", "花样年华-A29"};
  768. for (int i = 0; i < str.length; i++) {
  769. TProduct product = new TProduct();
  770. product.setCreateDate(new Date());
  771. product.setModifyDate(new Date());
  772. product.setEquipmentId(id);
  773. String[] split = str[i].split("-");
  774. product.setProductName(split[0]);
  775. product.setNo(split[1]);
  776. product.setRmbPrice(BigDecimal.ZERO);
  777. product.setCodePrice(BigDecimal.ZERO);
  778. productService.save(product);
  779. }
  780. }
  781. private void saveProductMG42(Long id) {
  782. String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09",
  783. "心之守护-A10", "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18",
  784. "精灵蝶梦-A19", "夏日倾城-A20", "百花齐放-A21", "蜂缠蝶恋-A22", "豆蔻年华-A23", "星空幻想-A24", "坠入星空-A25", "雪花飞舞-A26", "春暖花开-A27", "花飞蝶舞-A28",
  785. "花样年华-A29", "心花怒放-A30", "花好月圆-A37", "出水芙蓉-A38", "微光染晕-A39", "夏日莓莓-A40", "芳楚纷飞-A41", "晨夕光晕-A42", "坠入爱河-A43", "天马行空-A44",
  786. "灼灼其华-A45", "一帘幽梦-A46", "七月初夏-A47", "四月微风-A48"};
  787. for (int i = 0; i < str.length; i++) {
  788. TProduct product = new TProduct();
  789. product.setCreateDate(new Date());
  790. product.setModifyDate(new Date());
  791. product.setEquipmentId(id);
  792. String[] split = str[i].split("-");
  793. product.setProductName(split[0]);
  794. product.setNo(split[1]);
  795. product.setRmbPrice(BigDecimal.ZERO);
  796. product.setCodePrice(BigDecimal.ZERO);
  797. productService.save(product);
  798. }
  799. }
  800. /**
  801. * 添加爆米花产品
  802. *
  803. * @param id
  804. */
  805. private void saveProductP30(Long id) {
  806. String[] str = {"活力爆米花(正常糖)-B01", "活力爆米花(无糖)-B02", "活力爆米花(巧克力)-B03", "活力爆米花(焦糖)-B04", "活力爆米花(水蜜桃)-B05", "活力爆米花(蓝莓)-B06"};
  807. for (int i = 0; i < str.length; i++) {
  808. TProduct product = new TProduct();
  809. product.setCreateDate(new Date());
  810. product.setModifyDate(new Date());
  811. product.setEquipmentId(id);
  812. String[] split = str[i].split("-");
  813. product.setProductName(split[0]);
  814. product.setNo(split[1]);
  815. product.setRmbPrice(BigDecimal.ZERO);
  816. product.setCodePrice(BigDecimal.ZERO);
  817. productService.save(product);
  818. }
  819. }
  820. /**
  821. * 添加冰淇淋产品
  822. *
  823. * @param id
  824. */
  825. private void saveProductSI320(Long id) {
  826. LambdaQueryWrapper<TGoodsData> wrapper = Wrappers.lambdaQuery();
  827. wrapper.eq(TGoodsData::getNumber, 6);
  828. wrapper.eq(TGoodsData::getMachineType, "2");
  829. TGoodsData goodsData = goodsDataService.getOne(wrapper);
  830. String goods = goodsData.getGoods();
  831. String[] str = goods.split(",");
  832. for (int i = 0; i < str.length; i++) {
  833. TProduct product = new TProduct();
  834. product.setCreateDate(new Date());
  835. product.setModifyDate(new Date());
  836. product.setEquipmentId(id);
  837. String[] split = str[i].split("-");
  838. product.setProductName(split[0]);
  839. product.setNo(split[1]);
  840. product.setRmbPrice(new BigDecimal(0.01));
  841. product.setCodePrice(new BigDecimal(0.01));
  842. productService.save(product);
  843. }
  844. }
  845. /**
  846. * 获取指定日期所在月份开始的时间戳
  847. *
  848. * @param date 指定日期
  849. * @return
  850. */
  851. public static Long getMonthBegin(Date date) {
  852. Calendar c = Calendar.getInstance();
  853. c.setTime(date);
  854. //设置为10号,当前日期既为本月10号
  855. c.set(Calendar.DAY_OF_MONTH, 10);
  856. //将小时至0
  857. c.set(Calendar.HOUR_OF_DAY, 0);
  858. //将分钟至0
  859. c.set(Calendar.MINUTE, 0);
  860. //将秒至0
  861. c.set(Calendar.SECOND, 0);
  862. //将毫秒至0
  863. c.set(Calendar.MILLISECOND, 0);
  864. // 获取本月第一天的时间戳
  865. return c.getTimeInMillis();
  866. }
  867. public static Date nextMonthDate() {
  868. Calendar calendar = Calendar.getInstance();
  869. calendar.set(Calendar.DAY_OF_MONTH, 10);
  870. //将小时至0
  871. calendar.set(Calendar.HOUR_OF_DAY, 0);
  872. //将分钟至0
  873. calendar.set(Calendar.MINUTE, 0);
  874. //将秒至0
  875. calendar.set(Calendar.SECOND, 0);
  876. //将毫秒至0
  877. calendar.set(Calendar.MILLISECOND, 0);
  878. calendar.add(Calendar.MONTH, 1);
  879. return calendar.getTime();
  880. }
  881. /**
  882. * 改花型
  883. *
  884. * @param
  885. * @return
  886. */
  887. @RequestMapping(value = "/updateFlowers.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  888. @ResponseBody
  889. public String updateFlowers(String clientId, String number) {
  890. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  891. query.eq(TEquipment::getClientId, clientId);
  892. TEquipment equipment = equipmentService.getOne(query);
  893. if (equipment != null) {
  894. Long id = equipment.getId();
  895. //修改花型记录数目
  896. TEquipmentDesc equipmentDesc = equipmentDescService.getById(id);
  897. if (equipmentDesc != null) {
  898. equipmentDesc.setFlowers(number);
  899. equipmentDescService.updateById(equipmentDesc);
  900. } else {
  901. TEquipmentDesc equipmentDesc1 = new TEquipmentDesc();
  902. equipmentDesc1.setEquipmentId(id);
  903. equipmentDesc1.setFlowers(number);
  904. equipmentDescService.save(equipmentDesc1);
  905. }
  906. //删除旧花型
  907. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  908. queryProduct.eq(TProduct::getEquipmentId, equipment.getId());
  909. List<TProduct> productList = productService.list(queryProduct);
  910. for (TProduct product : productList) {
  911. productService.removeById(product.getId());
  912. }
  913. // 机器类型
  914. String machineType = equipment.getMachineType();
  915. if(StringUtils.isEmpty(equipment.getMachineType())) {
  916. machineType = "0";
  917. }
  918. //创建花型
  919. saveGoodsData(id, machineType, Integer.parseInt(number));
  920. // if (number.equals("18")) {
  921. // saveProduct(id);
  922. // }
  923. // if (number.equals("22")) {
  924. // saveProductMG22(id);
  925. // }
  926. // if (number.equals("26")) {
  927. // saveProductMG26(id);
  928. // }
  929. // if (number.equals("30")) {
  930. // saveProductMG1(id);
  931. // }
  932. // if (number.equals("42")) {
  933. // saveProductMG42(id);
  934. // }
  935. return "success";
  936. } else {
  937. return "error";
  938. }
  939. }
  940. /**
  941. * 设备类型 开机时上传
  942. *
  943. * @param clientId 个推
  944. * @return
  945. */
  946. @RequestMapping(value = "/equimentType.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  947. @ResponseBody
  948. public String equimentType(String clientId, String equimentType) {
  949. if (!StringUtils.isEmpty(equimentType)) {
  950. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  951. query.eq(TEquipment::getClientId, clientId);
  952. TEquipment equipment = equipmentService.getOne(query);
  953. equipment.setEquimentType(equimentType);
  954. equipmentService.updateById(equipment);
  955. }
  956. return "success";
  957. }
  958. /**
  959. * 设备地址 开机时上传
  960. *
  961. * @param clientId 个推
  962. * @return
  963. */
  964. @RequestMapping(value = "/equimentArea.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  965. @ResponseBody
  966. public String equimentArea(String clientId, String longitude, String latitude, String fullName) {
  967. if (!StringUtils.isEmpty(longitude) && !StringUtils.isEmpty(latitude) && !StringUtils.isEmpty(fullName)) {
  968. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  969. query.eq(TEquipment::getClientId, clientId);
  970. TEquipment equipment = equipmentService.getOne(query);
  971. equipment.setLatitude(Double.valueOf(latitude));
  972. equipment.setLongitude(Double.valueOf(longitude));
  973. equipment.setFullName(fullName + "-");
  974. equipmentService.updateById(equipment);
  975. return "success";
  976. }
  977. return "error";
  978. }
  979. /**
  980. * 商品调价
  981. */
  982. @RequestMapping(value = "/updateProduct.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  983. @ResponseBody
  984. public String updateProduct(@RequestBody List<ProductVo> productVos) {
  985. for (ProductVo product : productVos) {
  986. String clientId = product.getClientId();
  987. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  988. query.eq(TEquipment::getClientId, clientId);
  989. TEquipment equipment = equipmentService.getOne(query);
  990. Long id = equipment.getId();
  991. if (StringUtils.isNotEmpty(product.getShowType())) {
  992. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  993. queryProduct.eq(TProduct::getEquipmentId, id);
  994. queryProduct.eq(TProduct::getProductName, product.getProductName());
  995. TProduct tProduct = productService.getOnly(queryProduct);
  996. if (tProduct == null) {
  997. LambdaQueryWrapper<TNameDictionary> wrapper = Wrappers.lambdaQuery();
  998. wrapper.eq(TNameDictionary::getLanguage, "zh");
  999. wrapper.eq(TNameDictionary::getName, product.getProductName());
  1000. TNameDictionary nameDictionary = nameDictionaryService.getOne(wrapper);
  1001. LambdaQueryWrapper<TProduct> queryWrapper = Wrappers.lambdaQuery();
  1002. queryWrapper.eq(TProduct::getEquipmentId, id);
  1003. queryWrapper.eq(TProduct::getNo, nameDictionary.getNo());
  1004. tProduct = productService.getOnly(queryWrapper);
  1005. }
  1006. tProduct.setRmbPrice(BigDecimal.valueOf(product.getRmbPrice()));
  1007. tProduct.setCodePrice(BigDecimal.valueOf(product.getCodePrice()));
  1008. tProduct.setShowType(product.getShowType());
  1009. tProduct.setSellStatus(product.getSellStatus());
  1010. productService.updateById(tProduct);
  1011. } else {
  1012. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  1013. queryProduct.eq(TProduct::getEquipmentId, id);
  1014. queryProduct.eq(TProduct::getProductName, product.getProductName());
  1015. TProduct tProduct = productService.getOnly(queryProduct);
  1016. if (tProduct == null) {
  1017. LambdaQueryWrapper<TNameDictionary> wrapper = Wrappers.lambdaQuery();
  1018. wrapper.eq(TNameDictionary::getLanguage, "zh");
  1019. wrapper.eq(TNameDictionary::getName, product.getProductName());
  1020. TNameDictionary nameDictionary = nameDictionaryService.getOne(wrapper);
  1021. LambdaQueryWrapper<TProduct> queryWrapper = Wrappers.lambdaQuery();
  1022. queryWrapper.eq(TProduct::getEquipmentId, id);
  1023. queryWrapper.eq(TProduct::getNo, nameDictionary.getNo());
  1024. tProduct = productService.getOnly(queryWrapper);
  1025. }
  1026. tProduct.setRmbPrice(BigDecimal.valueOf(product.getRmbPrice()));
  1027. tProduct.setCodePrice(BigDecimal.valueOf(product.getCodePrice()));
  1028. tProduct.setSellStatus(product.getSellStatus());
  1029. productService.updateById(tProduct);
  1030. }
  1031. }
  1032. return "调价成功";
  1033. }
  1034. public Double tran(Double d) {
  1035. return new BigDecimal(d).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  1036. }
  1037. public Double tran2(Double d) {
  1038. return new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  1039. }
  1040. /**
  1041. * 密码修改
  1042. *
  1043. * @param clientId 设备个推Id
  1044. * @param pwdType 密码类型 1d代表修adminPwd,0代表guestPwd
  1045. * @return
  1046. * @Param pwd 密码内容
  1047. */
  1048. @RequestMapping(value = "/updatePwd.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1049. @ResponseBody
  1050. public String updatePwd(String clientId, String pwdType, String pwd) {
  1051. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1052. query.eq(TEquipment::getClientId, clientId);
  1053. TEquipment equipment = equipmentService.getOne(query);
  1054. if (equipment != null) {
  1055. if (!StringUtils.isEmpty(pwdType)) {
  1056. switch (pwdType) {
  1057. case "1":
  1058. equipment.setAdminPwd(pwd);
  1059. break;
  1060. case "0":
  1061. equipment.setGuestPwd(pwd);
  1062. break;
  1063. }
  1064. equipmentService.updateById(equipment);
  1065. return "更新密码成功";
  1066. }
  1067. }
  1068. return "更新密码失败";
  1069. }
  1070. /**
  1071. * 设备获取密码
  1072. */
  1073. @GetMapping(value = "/getPwd", produces = "text/html;charset=utf-8")
  1074. @ResponseBody
  1075. public String getPwd(String clientId) {
  1076. if (StringUtils.isEmpty(clientId)) {
  1077. return null;
  1078. }
  1079. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1080. query.eq(TEquipment::getClientId, clientId);
  1081. TEquipment equipment = equipmentService.getOne(query);
  1082. Map<String, String> map = new HashMap<>();
  1083. map.put("adminPwd", equipment.getAdminPwd());
  1084. map.put("guestPwd", equipment.getGuestPwd());
  1085. JSONObject jsonObject = new JSONObject();
  1086. jsonObject.put("code", 0);
  1087. jsonObject.put("data", JSONObject.toJSON(map).toString());
  1088. jsonObject.put("errmsg", "");
  1089. return jsonObject.toJSONString();
  1090. }
  1091. /**
  1092. * 修改支付方式
  1093. *
  1094. * @param clientId
  1095. * @param payType: 无需支付
  1096. * 线上支付
  1097. * 线下支付
  1098. * 线上/线下
  1099. * @return
  1100. */
  1101. @RequestMapping(value = "/updatePayType.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1102. @ResponseBody
  1103. public String updatePayType(String clientId, String payType) {
  1104. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1105. query.eq(TEquipment::getClientId, clientId);
  1106. TEquipment equipment = equipmentService.getOne(query);
  1107. if (equipment == null) {
  1108. return "修改支付方式失败";
  1109. }
  1110. equipment.setPayType(0);
  1111. equipmentService.updateById(equipment);
  1112. return "修改成功";
  1113. }
  1114. /**
  1115. * 日志上传
  1116. */
  1117. @RequestMapping(value = "/sendLog.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1118. @ResponseBody
  1119. public String uploadFile(HttpServletRequest request, HttpServletResponse response, String fileName) throws Exception {
  1120. // String fileFullPath = "/home/hboxs/log/" + fileName + ".txt";
  1121. //// String fileFullPath = "/root/uploadfile/apache-tomcat-8.5.42/" + fileName;
  1122. //
  1123. // InputStream input = null;
  1124. // FileOutputStream fos = null;
  1125. // try {
  1126. // input = request.getInputStream();
  1127. // File file = new File("/home/hboxs/log/");
  1128. // if (!file.exists()) {
  1129. // file.mkdirs();
  1130. // }
  1131. // fos = new FileOutputStream(fileFullPath);
  1132. // int size = 0;
  1133. // byte[] buffer = new byte[1024];
  1134. // while ((size = input.read(buffer, 0, 1024)) != -1) {
  1135. // fos.write(buffer, 0, size);
  1136. // }
  1137. //
  1138. // //响应信息 json字符串格式
  1139. // Map<String, Object> responseMap = new HashMap<String, Object>();
  1140. // responseMap.put("flag", true);
  1141. //
  1142. // //生成响应的json字符串
  1143. // String jsonResponse = JSONObject.toJSONString(responseMap);
  1144. // sendResponse(jsonResponse, response);
  1145. // } catch (IOException e) {
  1146. // //响应信息 json字符串格式
  1147. // Map<String, Object> responseMap = new HashMap<String, Object>();
  1148. // responseMap.put("flag", false);
  1149. // responseMap.put("errorMsg", e.getMessage());
  1150. // String jsonResponse = JSONObject.toJSONString(responseMap) ;
  1151. // sendResponse(jsonResponse, response);
  1152. // } finally {
  1153. // if (input != null) {
  1154. // input.close();
  1155. // }
  1156. // if (fos != null) {
  1157. // fos.close();
  1158. // }
  1159. // }
  1160. //构造一个带指定 Region 对象的配置类
  1161. Configuration cfg = new Configuration(Region.region2());
  1162. cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;// 指定分片上传版本
  1163. UploadManager uploadManager = new UploadManager(cfg);
  1164. //默认不指定key的情况下,以文件内容的hash值作为文件名
  1165. String key = "log/" + fileName + ".txt";
  1166. try {
  1167. ServletInputStream input = request.getInputStream();
  1168. Auth auth = Auth.create(ConfigConsts.QINIU_CLOUD_ACCESS_KEY, ConfigConsts.QINIU_CLOUD_SECRET_KEY);
  1169. String upToken = auth.uploadToken(ConfigConsts.QINIU_CLOUD_BUCKET, key);
  1170. Response responseMap = uploadManager.put(input, key, upToken, null, null);
  1171. //解析上传成功的结果
  1172. DefaultPutRet putRet = new Gson().fromJson(responseMap.bodyString(), DefaultPutRet.class);
  1173. System.out.println(putRet.key);
  1174. System.out.println(putRet.hash);
  1175. } catch (Exception ex) {
  1176. //响应信息 json字符串格式
  1177. Map<String, Object> responseMap = new HashMap<String, Object>();
  1178. responseMap.put("flag", false);
  1179. responseMap.put("errorMsg", ex.getMessage());
  1180. String jsonResponse = JSONObject.toJSONString(responseMap);
  1181. sendResponse(jsonResponse, response);
  1182. }
  1183. return "success";
  1184. }
  1185. /**
  1186. * 返回响应
  1187. *
  1188. * @throws Exception
  1189. */
  1190. private void sendResponse(String responseString, HttpServletResponse response) throws Exception {
  1191. response.setContentType("application/json;charset=UTF-8");
  1192. PrintWriter pw = null;
  1193. try {
  1194. pw = response.getWriter();
  1195. pw.write(responseString);
  1196. pw.flush();
  1197. } finally {
  1198. IOUtils.closeQuietly(pw);
  1199. }
  1200. }
  1201. /**
  1202. * 脱离系统
  1203. *
  1204. * @param clientId
  1205. * @return
  1206. */
  1207. @RequestMapping(value = "/separate.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1208. @ResponseBody
  1209. public String separate(String clientId) {
  1210. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1211. query.eq(TEquipment::getClientId, clientId);
  1212. TEquipment equipment = equipmentService.getOne(query);
  1213. if (equipment == null) {
  1214. return "该设备不存在";
  1215. }
  1216. equipmentService.sentMessage(clientId, PushUtils.buildJson("tuoji", "0").toString());
  1217. if ("xxx".equals(equipment.getClientId().substring(equipment.getClientId().length() - 3, equipment.getClientId().length()))) {
  1218. return "脱离成功";
  1219. }
  1220. equipment.setClientId(equipment.getClientId() + "xxx");
  1221. equipmentService.updateById(equipment);
  1222. return "脱离成功";
  1223. }
  1224. /**
  1225. * 脱离系统
  1226. *
  1227. * @param clientId
  1228. * @return
  1229. */
  1230. @RequestMapping(value = "/updateClientId", method = RequestMethod.POST)
  1231. @ResponseBody
  1232. public String updateClientId(String clientId) {
  1233. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1234. query.eq(TEquipment::getClientId, clientId);
  1235. TEquipment equipment = equipmentService.getOne(query);
  1236. if (equipment == null) {
  1237. return "该设备不存在";
  1238. }
  1239. if ("xxx".equals(equipment.getClientId().substring(equipment.getClientId().length() - 3, equipment.getClientId().length()))) {
  1240. return "脱离成功";
  1241. }
  1242. equipment.setClientId(equipment.getClientId() + "xxx");
  1243. equipment.setManagerId(null);
  1244. equipmentService.updateById(equipment);
  1245. return "脱离成功";
  1246. }
  1247. /**
  1248. * 修改设备联系人名称以及电话
  1249. */
  1250. @RequestMapping(value = "/updateContractPN.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1251. @ResponseBody
  1252. public String updateContractPN(String clientId, String contactName, String contactPhone) {
  1253. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1254. query.eq(TEquipment::getClientId, clientId);
  1255. TEquipment equipment = equipmentService.getOne(query);
  1256. if (equipment == null) {
  1257. return "该设备不存在";
  1258. }
  1259. equipment.setContactName(contactName);
  1260. equipment.setContactPhone(contactPhone);
  1261. equipmentService.updateById(equipment);
  1262. return "修改成功";
  1263. }
  1264. /**
  1265. * 设备上传公司电话
  1266. */
  1267. @RequestMapping(value = "/sentCompanyPhone.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1268. @ResponseBody
  1269. public String sentCompanyPhone(String clientId, String companyPhone) {
  1270. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1271. query.eq(TEquipment::getClientId, clientId);
  1272. TEquipment equipment = equipmentService.getOne(query);
  1273. if (equipment == null) {
  1274. return "该设备不存在";
  1275. }
  1276. equipment.setCompanyPhone(companyPhone);
  1277. equipmentService.updateById(equipment);
  1278. return "修改成功";
  1279. }
  1280. /**
  1281. * 获取二维码图片
  1282. */
  1283. @RequestMapping(value = "/getQrCodeImgUrl.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1284. @ResponseBody
  1285. public String getQrCodeImgUrl(String clientId) {
  1286. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1287. query.eq(TEquipment::getClientId, clientId);
  1288. TEquipment equipment = equipmentService.getOne(query);
  1289. if (equipment == null) {
  1290. return "404";
  1291. }
  1292. return "400";
  1293. }
  1294. /**
  1295. * 上传4G卡号
  1296. */
  1297. @RequestMapping(value = "/sentSimNo.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1298. @ResponseBody
  1299. public String sentSimNo(String clientId, String simNo) {
  1300. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1301. query.eq(TEquipment::getClientId, clientId);
  1302. TEquipment equipment = equipmentService.getOne(query);
  1303. if (equipment == null) {
  1304. return "该设备不存在";
  1305. }
  1306. equipment.setSimNo(simNo);
  1307. equipmentService.updateById(equipment);
  1308. return "修改成功";
  1309. }
  1310. /**
  1311. * 上传机器的apk版本
  1312. */
  1313. @RequestMapping(value = "/sendApkVersion.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1314. @ResponseBody
  1315. public String sendApkVersion(String clientId, String apkVersion) {
  1316. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1317. query.eq(TEquipment::getClientId, clientId);
  1318. TEquipment equipment = equipmentService.getOne(query);
  1319. if (equipment == null) {
  1320. return "该设备不存在";
  1321. }
  1322. equipment.setApkVersion(apkVersion);
  1323. equipmentService.updateById(equipment);
  1324. return "success";
  1325. }
  1326. /**
  1327. * 上传机器的做糖状态
  1328. */
  1329. @RequestMapping(value = "/equipmentStatus.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1330. @ResponseBody
  1331. public String equipmentStatus(String clientId, String status) {
  1332. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1333. query.eq(TEquipment::getClientId, clientId);
  1334. TEquipment equipment = equipmentService.getOne(query);
  1335. if (equipment == null) {
  1336. return "该设备不存在";
  1337. }
  1338. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  1339. //机器状态;0:空闲,1:在做糖;
  1340. equipmentDesc.setStatus(status);
  1341. equipmentDescService.updateById(equipmentDesc);
  1342. return "success";
  1343. }
  1344. /**
  1345. * 修改设备状态
  1346. *
  1347. * @param clientId
  1348. * @param eqeStatus 设备状态1开 0关
  1349. * @return
  1350. */
  1351. @RequestMapping(value = "/updateEqeStatus.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1352. @ResponseBody
  1353. public String updateEqeStatus(String clientId, Integer eqeStatus) {
  1354. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1355. query.eq(TEquipment::getClientId, clientId);
  1356. TEquipment equipment = equipmentService.getOne(query);
  1357. if (equipment == null) {
  1358. return "该设备不存在";
  1359. }
  1360. if (eqeStatus != null) {
  1361. equipment.setEqeStatus(eqeStatus);
  1362. equipment.setModifyDate(new Date());
  1363. equipmentService.updateById(equipment);
  1364. }
  1365. return "修改成功";
  1366. }
  1367. /**
  1368. * 新修改设备状态
  1369. *
  1370. * @param clientId
  1371. * @param eqeStatus 设备状态1开 0关
  1372. * @return
  1373. */
  1374. @RequestMapping(value = "/updateEqeStatusNew.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1375. @ResponseBody
  1376. public String updateEqeStatusNew(String clientId, Integer eqeStatus, String netTime) {
  1377. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1378. query.eq(TEquipment::getClientId, clientId);
  1379. TEquipment equipment = equipmentService.getOne(query);
  1380. if (equipment == null) {
  1381. return "该设备不存在";
  1382. }
  1383. if (eqeStatus != null) {
  1384. equipment.setNetwork(netTime);
  1385. equipment.setEqeStatus(eqeStatus);
  1386. equipmentService.updateById(equipment);
  1387. }
  1388. return "修改成功";
  1389. }
  1390. /**
  1391. * 修改设备锁定状态
  1392. *
  1393. * @param clientId
  1394. * @param block
  1395. * @return
  1396. */
  1397. @RequestMapping(value = "/updateBlock.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1398. @ResponseBody
  1399. public String updateBlock(String clientId, Boolean block) {
  1400. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1401. query.eq(TEquipment::getClientId, clientId);
  1402. TEquipment equipment = equipmentService.getOne(query);
  1403. if (equipment == null) {
  1404. return "该设备不存在";
  1405. }
  1406. equipment.setIsBlocked(block);
  1407. equipmentService.updateById(equipment);
  1408. return "修改成功";
  1409. }
  1410. /**
  1411. * 修改设备睡眠状态
  1412. *
  1413. * @param clientId
  1414. * @param is_sleep
  1415. * @return
  1416. */
  1417. @RequestMapping(value = "/updateSleep.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1418. @ResponseBody
  1419. public String updateSleep(String clientId, Boolean is_sleep) {
  1420. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1421. query.eq(TEquipment::getClientId, clientId);
  1422. TEquipment equipment = equipmentService.getOne(query);
  1423. if (equipment == null) {
  1424. return "该设备不存在";
  1425. }
  1426. if (is_sleep != null) {
  1427. equipment.setIsSleep(is_sleep);
  1428. equipmentService.updateById(equipment);
  1429. }
  1430. return "修改成功";
  1431. }
  1432. /**
  1433. * 修改设备生产棉花糖个数
  1434. *
  1435. * @param clientId
  1436. * @param productTotal
  1437. * @return
  1438. */
  1439. @RequestMapping(value = "/updateProductTotal.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1440. @ResponseBody
  1441. public String updateProductTotal(String clientId, Integer productTotal) {
  1442. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1443. query.eq(TEquipment::getClientId, clientId);
  1444. TEquipment equipment = equipmentService.getOne(query);
  1445. if (equipment == null) {
  1446. return "该设备不存在";
  1447. }
  1448. Integer total = equipment.getProductTotal();
  1449. if (total == null) {
  1450. total = 0;
  1451. }
  1452. equipment.setProductTotal(total + productTotal);
  1453. equipmentService.updateById(equipment);
  1454. return "修改成功";
  1455. }
  1456. /**
  1457. * 修改设备共同参数/进阶参数
  1458. *
  1459. * @param
  1460. * @return
  1461. */
  1462. // @PostMapping(value = "/updateParam/{code}/{clientId}", produces = "application/json;charset=UTF-8")
  1463. // @ResponseBody
  1464. // public JsonMessage updateParam(@PathVariable Integer code, @PathVariable String clientId, @RequestBody List<CommonParamVo> commonParamVos) {
  1465. // Equipment equipment = equipmentService.findByClientId(clientId);
  1466. // if (equipment == null) {
  1467. // return JsonMessage.error("设备不存在");
  1468. // }
  1469. // String param = JSONArray.toJSONString(commonParamVos);
  1470. // if (code == 0) {
  1471. // equipment.setCommonParameters(param);
  1472. // } else {
  1473. // equipment.setAdvancedParameters(param);
  1474. // }
  1475. // equipmentService.update(equipment);
  1476. // return JsonMessage.success("修改成功");
  1477. // }
  1478. /**
  1479. * 修改设备共同参数/进阶参数
  1480. * code 0:通用参数;1:进阶参数;2:调试页参数;3:湿度参数
  1481. *
  1482. * @param
  1483. * @return
  1484. */
  1485. @RequestMapping(value = "/updateParamNew", method = RequestMethod.POST)
  1486. @ResponseBody
  1487. public String updateParamNew(Integer code, String clientId, @RequestBody List<CommonParamVo> commonParamVos) {
  1488. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1489. query.eq(TEquipment::getClientId, clientId);
  1490. TEquipment equipment = equipmentService.getOne(query);
  1491. if (equipment == null) {
  1492. return "设备不存在";
  1493. }
  1494. if (commonParamVos.size() <= 0) {
  1495. return "参数为空";
  1496. }
  1497. LambdaQueryWrapper<TParameters> queryParameters = Wrappers.lambdaQuery();
  1498. queryParameters.eq(TParameters::getClientId, clientId);
  1499. queryParameters.eq(TParameters::getStatus, code);
  1500. queryParameters.eq(TParameters::getEquipmentId, equipment.getId());
  1501. List<TParameters> list = parametersService.list(queryParameters);
  1502. if (list.size() > 0) {
  1503. for (TParameters parameters : list) {
  1504. //删除旧的参数
  1505. parametersService.removeById(parameters.getId());
  1506. }
  1507. }
  1508. Date date = new Date();
  1509. for (CommonParamVo commonParamVo : commonParamVos) {
  1510. TParameters parameters = new TParameters();
  1511. parameters.setVal(commonParamVo.getVal());
  1512. parameters.setName(commonParamVo.getName());
  1513. parameters.setStatus(String.valueOf(code));
  1514. parameters.setClientId(clientId);
  1515. parameters.setEquipmentId(equipment.getId());
  1516. parameters.setCreateDate(date);
  1517. parameters.setModifyDate(date);
  1518. parametersService.save(parameters);
  1519. }
  1520. return "修改成功";
  1521. }
  1522. /**
  1523. * 修改单个设备共同参数/进阶参数
  1524. * code 0:通用参数;1:进阶参数;2:调试页参数;3:湿度参数
  1525. *
  1526. * @param
  1527. * @return
  1528. */
  1529. @PostMapping(value = "/updateAloneParam.htm", produces = "text/html;charset=utf-8")
  1530. @ResponseBody
  1531. public String updateAloneParam(String code, String clientId, String name, String val) {
  1532. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1533. query.eq(TEquipment::getClientId, clientId);
  1534. TEquipment equipment = equipmentService.getOne(query);
  1535. if (equipment == null) {
  1536. return "设备不存在";
  1537. }
  1538. LambdaQueryWrapper<TParameters> queryParameters = Wrappers.lambdaQuery();
  1539. queryParameters.eq(TParameters::getClientId, clientId);
  1540. queryParameters.eq(TParameters::getStatus, code);
  1541. queryParameters.eq(TParameters::getName, name);
  1542. queryParameters.eq(TParameters::getEquipmentId, equipment.getId());
  1543. List<TParameters> list1 = parametersService.list(queryParameters);
  1544. if (list1.size() > 0) {
  1545. TParameters parameters = list1.get(0);
  1546. parameters.setVal(val);
  1547. parameters.setModifyDate(new Date());
  1548. parametersService.updateById(parameters);
  1549. }
  1550. return "修改成功";
  1551. }
  1552. /**
  1553. * 获取机器列表
  1554. */
  1555. @RequestMapping(value = "/getEquipmentList.htm", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
  1556. @ResponseBody
  1557. public String getByAdminAndProduct(String adminId, String name) {
  1558. JSONObject jsonObject = new JSONObject();
  1559. if (StringUtils.isEmpty(adminId)) {
  1560. jsonObject.put("code", 1);
  1561. jsonObject.put("errmsg", "adminId为空");
  1562. return jsonObject.toJSONString();
  1563. }
  1564. if (StringUtils.isEmpty(name)) {
  1565. jsonObject.put("code", 1);
  1566. jsonObject.put("errmsg", "name为空");
  1567. return jsonObject.toJSONString();
  1568. }
  1569. TAdmin admin = adminService.getById(adminId);
  1570. if (!admin.getUsername().equals(name)) {
  1571. jsonObject.put("code", 1);
  1572. jsonObject.put("errmsg", "name与adminId不匹配");
  1573. return jsonObject.toJSONString();
  1574. }
  1575. List<EquipmentDTO> list = new ArrayList<>();
  1576. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1577. query.eq(TEquipment::getAdminId, Long.valueOf(adminId));
  1578. List<TEquipment> equipmentList = equipmentService.list(query);
  1579. for (TEquipment equipment : equipmentList) {
  1580. EquipmentDTO equipmentDTO = new EquipmentDTO();
  1581. equipmentDTO.setClientId(equipment.getClientId());
  1582. equipmentDTO.setSn(equipment.getSn());
  1583. equipmentDTO.setName(equipment.getName());
  1584. equipmentDTO.setLatitude(equipment.getLatitude());
  1585. equipmentDTO.setLongitude(equipment.getLongitude());
  1586. equipmentDTO.setFullName(equipment.getFullName());
  1587. equipmentDTO.setEqeStatus(equipment.getEqeStatus());
  1588. list.add(equipmentDTO);
  1589. }
  1590. jsonObject.put("code", 0);
  1591. jsonObject.put("rows", JsonUtils.toJson(list));
  1592. jsonObject.put("errmsg", "");
  1593. jsonObject.put("total", list.size());
  1594. return jsonObject.toJSONString();
  1595. }
  1596. /**
  1597. * 获取商品信息
  1598. */
  1599. @RequestMapping(value = "/getProductions.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1600. @ResponseBody
  1601. public String getProductions(String adminId, String clientId) {
  1602. JSONObject jsonObject = new JSONObject();
  1603. if (StringUtils.isEmpty(adminId)) {
  1604. jsonObject.put("code", 1);
  1605. jsonObject.put("errmsg", "adminId为空");
  1606. return jsonObject.toJSONString();
  1607. }
  1608. if (StringUtils.isEmpty(clientId)) {
  1609. jsonObject.put("code", 1);
  1610. jsonObject.put("errmsg", "clientId为空");
  1611. return jsonObject.toJSONString();
  1612. }
  1613. TAdmin admin = adminService.getById(Long.valueOf(adminId));
  1614. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1615. query.eq(TEquipment::getClientId, clientId);
  1616. TEquipment equipment = equipmentService.getOne(query);
  1617. if (!equipment.getAdminId().toString().equals(admin.getId().toString())) {
  1618. jsonObject.put("code", 1);
  1619. jsonObject.put("errmsg", "clientId与adminId不匹配");
  1620. return jsonObject.toJSONString();
  1621. }
  1622. List<String> list = new ArrayList<>();
  1623. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  1624. queryProduct.eq(TProduct::getEquipmentId, equipment.getId());
  1625. List<TProduct> products = productService.list(queryProduct);
  1626. for (TProduct product : products) {
  1627. list.add(product.getProductName());
  1628. }
  1629. jsonObject.put("code", 0);
  1630. jsonObject.put("productions", JsonUtils.toJson(list));
  1631. jsonObject.put("errmsg", "");
  1632. jsonObject.put("total", list.size());
  1633. return jsonObject.toJSONString();
  1634. }
  1635. /**
  1636. * 根据设备编号获取商品信息
  1637. */
  1638. @RequestMapping(value = "/getproducts", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1639. @ResponseBody
  1640. public String getproducts(String clientId) {
  1641. JSONObject jsonObject = new JSONObject();
  1642. if (StringUtils.isEmpty(clientId)) {
  1643. jsonObject.put("code", 1);
  1644. jsonObject.put("errmsg", "clientId为空");
  1645. return jsonObject.toJSONString();
  1646. }
  1647. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1648. query.eq(TEquipment::getClientId, clientId);
  1649. TEquipment equipment = equipmentService.getOne(query);
  1650. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  1651. queryProduct.eq(TProduct::getEquipmentId, equipment.getId());
  1652. List<TProduct> products = productService.list(queryProduct);
  1653. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  1654. for (TProduct product : products) {
  1655. product.setCreateDate(null);
  1656. product.setModifyDate(null);
  1657. if (StringUtils.isNotEmpty(equipmentDesc.getLanguage()) && !equipmentDesc.getLanguage().equals("zh") && StringUtils.isEmpty(product.getName())) {
  1658. LambdaQueryWrapper<TNameDictionary> queryWrapper = new LambdaQueryWrapper<>();
  1659. queryWrapper.eq(TNameDictionary::getLanguage, "zh");
  1660. queryWrapper.eq(TNameDictionary::getNo, product.getNo());
  1661. TNameDictionary nameDictionary = nameDictionaryService.getOne(queryWrapper);
  1662. if (nameDictionary != null) {
  1663. product.setProductName(nameDictionary.getName());
  1664. }
  1665. }
  1666. }
  1667. JSONObject jsonObject1 = new JSONObject();
  1668. jsonObject1.put("code", 0);
  1669. jsonObject1.put("data", JSONObject.toJSON(products).toString());
  1670. jsonObject1.put("errmsg", "");
  1671. return JSONObject.toJSON(products).toString();
  1672. }
  1673. /**
  1674. * 是否启用物料监控功能
  1675. * 0:不启用,1:启用
  1676. *
  1677. * @param clientId 个推
  1678. * @return
  1679. */
  1680. @RequestMapping(value = "/updateMaterialStatus.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1681. @ResponseBody
  1682. public String updateMaterialUse(String clientId, String isMaterialUse) {
  1683. if (!StringUtils.isEmpty(clientId) && !StringUtils.isEmpty(isMaterialUse)) {
  1684. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1685. query.eq(TEquipment::getClientId, clientId);
  1686. TEquipment equipment = equipmentService.getOne(query);
  1687. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  1688. equipmentDesc.setIsMaterialUse(isMaterialUse);
  1689. equipmentDescService.updateById(equipmentDesc);
  1690. // 改变参数表里的状态
  1691. LambdaQueryWrapper<TParameters> queryWrapper = Wrappers.lambdaQuery();
  1692. queryWrapper.eq(TParameters::getClientId, clientId);
  1693. queryWrapper.eq(TParameters::getName, "M502");
  1694. TParameters parameters = parametersService.getOne(queryWrapper);
  1695. if (Objects.nonNull(parameters)) {
  1696. parameters.setVal(isMaterialUse);
  1697. parametersService.updateById(parameters);
  1698. }
  1699. return "success";
  1700. }
  1701. return "error";
  1702. }
  1703. //修改优惠码状态
  1704. @RequestMapping(value = "/updateCode.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1705. @ResponseBody
  1706. public String CardPay(String code, String clientId) {
  1707. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1708. query.eq(TEquipment::getClientId, clientId);
  1709. TEquipment equipment = equipmentService.getOne(query);
  1710. LambdaQueryWrapper<TPromoCode> query1 = Wrappers.lambdaQuery();
  1711. query1.eq(TPromoCode::getAdminId, equipment.getAdminId());
  1712. query1.eq(TPromoCode::getCode, code);
  1713. List<TPromoCode> list1 = promoCodeService.list(query1);
  1714. TPromoCode promoCode = list1.get(0);
  1715. promoCode.setIsUse("1");
  1716. promoCode.setUseBy(equipment.getName());
  1717. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1718. String time = sdf.format(new Date());
  1719. promoCode.setUseDate(time);
  1720. promoCodeService.updateById(promoCode);
  1721. return "success";
  1722. }
  1723. //验证优惠码
  1724. @RequestMapping(value = "/selectCode.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1725. @ResponseBody
  1726. public String selectCode(String code, String clientId) {
  1727. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1728. query.eq(TEquipment::getClientId, clientId);
  1729. TEquipment equipment = equipmentService.getOne(query);
  1730. //验证优惠码
  1731. LambdaQueryWrapper<TPromoCode> query1 = Wrappers.lambdaQuery();
  1732. query1.eq(TPromoCode::getCode, code);
  1733. List<TPromoCode> codeList = promoCodeService.list(query1);
  1734. TPromoCode promoCode = new TPromoCode();
  1735. if (codeList.size() == 0) {
  1736. //不存在
  1737. return "1";
  1738. }
  1739. for (TPromoCode cod : codeList) {
  1740. if (!cod.getAdminId().equals("1")) {
  1741. String adminId = cod.getAdminId();
  1742. String adminId1 = String.valueOf(equipment.getAdminId());
  1743. if (adminId.equals(adminId1)) {
  1744. promoCode = cod;
  1745. }
  1746. } else {
  1747. promoCode = cod;
  1748. }
  1749. }
  1750. if (promoCode.getAdminId() == null) {
  1751. //不是本机
  1752. return "3";
  1753. }
  1754. Date lastUseDate = null;
  1755. if (promoCode != null) {
  1756. lastUseDate = promoCode.getLastUseDate();
  1757. }
  1758. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  1759. promoCode.setIsUse("2");
  1760. promoCodeService.updateById(promoCode);
  1761. //过期
  1762. return "4";
  1763. }
  1764. if (promoCode.getId() == null) {
  1765. //不存在
  1766. return "1";
  1767. }
  1768. if (promoCode.getIsUse().equals("1")) {
  1769. //被使用
  1770. return "2";
  1771. }
  1772. if (!promoCode.getAdminId().equals("1")) {
  1773. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  1774. } else {
  1775. //不是本机
  1776. return "3";
  1777. }
  1778. }
  1779. if (promoCode.getDiscount() == null) {
  1780. //旧优惠码
  1781. return "0";
  1782. }
  1783. if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
  1784. //0折
  1785. return "0";
  1786. }
  1787. return "success";
  1788. }
  1789. //修改机器的分销
  1790. @RequestMapping(value = "/updateProportion.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1791. @ResponseBody
  1792. public String updateProportion(String clientId) {
  1793. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1794. query.eq(TEquipment::getClientId, clientId);
  1795. TEquipment equipment = equipmentService.getOne(query);
  1796. if (equipment != null && equipment.getId() != null) {
  1797. TAdmin admin = adminService.getById(equipment.getAdminId());
  1798. String name = admin.getName();
  1799. //查询机器是否已经有设置分销
  1800. LambdaQueryWrapper<TProportion> query1 = Wrappers.lambdaQuery();
  1801. query1.eq(TProportion::getClientId, equipment.getClientId());
  1802. query1.eq(TProportion::getEquipmentId, equipment.getId());
  1803. List<TProportion> list1 = proportionService.list(query1);
  1804. if (list1.size() > 0) {
  1805. //已有
  1806. } else {
  1807. //没有,需要创建
  1808. //1,判断是否新机器
  1809. // Date createDate = equipment.getCreateDate();
  1810. // long time = createDate.getTime();
  1811. // DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1812. // String day= "2022-09-21 23:59:59";
  1813. // try {
  1814. // Date parse = simpleDateFormat.parse(day);
  1815. // if(time>parse.getTime()){
  1816. // return "新机器,不能已此方式生成分销!";
  1817. // }
  1818. // } catch (ParseException e) {
  1819. // e.printStackTrace();
  1820. // }
  1821. //先找到原账户的分销
  1822. LambdaQueryWrapper<TProportion> query2 = Wrappers.lambdaQuery();
  1823. query2.eq(TProportion::getAdminId, admin.getId());
  1824. List<TProportion> list2 = proportionService.list(query2);
  1825. if (list2.size() > 0) {
  1826. TProportion adminProportion = list2.get(0);
  1827. if (StringUtils.isEmpty(adminProportion.getClientId())) {
  1828. TProportion equipmentProportion = new TProportion();
  1829. equipmentProportion.setCreateDate(new Date());
  1830. equipmentProportion.setModifyDate(new Date());
  1831. equipmentProportion.setAdminId(admin.getId());
  1832. equipmentProportion.setClientId(equipment.getClientId());
  1833. equipmentProportion.setEquipmentId(equipment.getId());
  1834. equipmentProportion.setAdminProportion(adminProportion.getAdminProportion());
  1835. Integer type = adminProportion.getType();
  1836. switch (type) {
  1837. case 1:
  1838. equipmentProportion.setProportion(adminProportion.getAgencyProportion());
  1839. equipmentProportion.setAgencyProportion(new BigDecimal("0.00"));
  1840. equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
  1841. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  1842. equipmentProportion.setType(0);
  1843. break;
  1844. case 2:
  1845. equipmentProportion.setProportion(adminProportion.getMerchantProportion());
  1846. equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
  1847. equipmentProportion.setAgencyId(admin.getAgencyId());
  1848. TAdmin byId = adminService.getById(admin.getAgencyId());
  1849. equipmentProportion.setAgencyName(byId.getUsername());
  1850. equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
  1851. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  1852. equipmentProportion.setType(1);
  1853. break;
  1854. case 3:
  1855. equipmentProportion.setProportion(adminProportion.getPersonageProportion());
  1856. equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
  1857. equipmentProportion.setAgencyId(admin.getAgencyId());
  1858. TAdmin byId1 = adminService.getById(admin.getAgencyId());
  1859. equipmentProportion.setAgencyName(byId1.getUsername());
  1860. equipmentProportion.setMerchantProportion(adminProportion.getMerchantProportion());
  1861. equipmentProportion.setMerchantId(admin.getMerchantId());
  1862. TAdmin byId2 = adminService.getById(admin.getMerchantId());
  1863. equipmentProportion.setMerchantName(byId2.getUsername());
  1864. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  1865. equipmentProportion.setType(2);
  1866. break;
  1867. }
  1868. boolean save = proportionService.save(equipmentProportion);
  1869. }
  1870. } else {
  1871. return "原账户没有设置分销!";
  1872. }
  1873. }
  1874. }
  1875. return "success";
  1876. }
  1877. /**
  1878. * @param clientId
  1879. * @return
  1880. */
  1881. @GetMapping(value = "/getManagerId.htm")
  1882. @ResponseBody
  1883. public String getManagerId(String clientId) {
  1884. if (!StringUtils.isEmpty(clientId)) {
  1885. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1886. query.eq(TEquipment::getClientId, clientId);
  1887. List<TEquipment> list = equipmentService.list(query);
  1888. if (list.size() > 0) {
  1889. TEquipment equipment = list.get(0);
  1890. Long adminId = equipment.getAdminId();
  1891. if (adminId != null) {
  1892. String managerId = AdminUtils.encrypt(false, adminId);
  1893. if (StringUtils.isEmpty(equipment.getManagerId()) || !equipment.getManagerId().equals(managerId)) {
  1894. equipment.setManagerId(managerId);
  1895. equipmentService.updateById(equipment);
  1896. }
  1897. return managerId;
  1898. }
  1899. }
  1900. return "error";
  1901. }
  1902. return "error";
  1903. }
  1904. /**
  1905. * 修改优惠券开关状态
  1906. *
  1907. * @param clientId
  1908. * @return
  1909. */
  1910. @GetMapping(value = "/updateCouponStatus.htm")
  1911. @ResponseBody
  1912. public String updateCouponStatus(String clientId, String couponStatus) {
  1913. if (!StringUtils.isEmpty(clientId) && StringUtils.isNotEmpty(couponStatus)) {
  1914. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1915. query.eq(TEquipment::getClientId, clientId);
  1916. TEquipment equipment = equipmentService.getOne(query);
  1917. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  1918. equipmentDesc.setCouponStatus(couponStatus);
  1919. equipmentDescService.updateById(equipmentDesc);
  1920. TAdmin admin = adminService.getById(equipment.getAdminId());
  1921. //同步数据到鲸准
  1922. if (admin.getId().toString().equals("372") || admin.getRelationAdminId().equals("372") || admin.getId().toString().equals("639") || admin.getId().toString().equals("238")) {
  1923. sendCouponStatus(clientId, equipment.getFullName(), equipment.getEqeStatus(), couponStatus);
  1924. }
  1925. return "success";
  1926. }
  1927. return "error";
  1928. }
  1929. private void sendCouponStatus(String clientId, String fullName, Integer eqeStatus, String couponStatus) {
  1930. String url = "http://47.106.13.109:3000/api/listenDeviceStatusChange";
  1931. Map<String, String> map = new HashMap<>();
  1932. map.put("clientId", clientId);
  1933. map.put("address", fullName);
  1934. map.put("status", String.valueOf(eqeStatus));
  1935. if (StringUtils.isEmpty(couponStatus)) {
  1936. map.put("wxStatus", "1");
  1937. } else {
  1938. map.put("wxStatus", couponStatus);
  1939. }
  1940. String data = JSON.toJSONString(map);
  1941. try {
  1942. String s = HttpClientSslUtils.doPost(url, data);
  1943. System.out.println("发送鲸准:" + s);
  1944. } catch (Exception e) {
  1945. e.printStackTrace();
  1946. }
  1947. }
  1948. /**
  1949. * @param clientId
  1950. * @return
  1951. */
  1952. @GetMapping(value = "/getYouHuiPrice.htm")
  1953. @ResponseBody
  1954. public String getYouHuiPrice(String clientId) {
  1955. LambdaQueryWrapper<TPrice> query = Wrappers.lambdaQuery();
  1956. query.eq(TPrice::getName, "优惠券");
  1957. List<TPrice> list = priceService.list(query);
  1958. if (list.size() > 0) {
  1959. TPrice tPrice = list.get(0);
  1960. Double price = tPrice.getPrice();
  1961. return new BigDecimal(price).setScale(0, RoundingMode.HALF_DOWN).toString();
  1962. } else {
  1963. return "5";
  1964. }
  1965. }
  1966. /**
  1967. * 修改商品名称
  1968. *
  1969. * @param clientId 设备个推Id
  1970. * @param
  1971. * @return
  1972. * @Param
  1973. */
  1974. @RequestMapping(value = "/updateProductName.htm", method = RequestMethod.POST)
  1975. @ResponseBody
  1976. public String updateProductName(String clientId, Long productId, String oldProductName, String newProductName) {
  1977. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1978. query.eq(TEquipment::getClientId, clientId);
  1979. List<TEquipment> list = equipmentService.list(query);
  1980. if (list.size() > 0) {
  1981. TEquipment equipment = list.get(0);
  1982. if (equipment != null && equipment.getId() != null) {
  1983. TProduct product = productService.getById(productId);
  1984. product.setModifyDate(new Date());
  1985. product.setName(oldProductName);
  1986. product.setProductName(newProductName);
  1987. productService.updateById(product);
  1988. return "修改成功success!";
  1989. }
  1990. }
  1991. return "更新失败error";
  1992. }
  1993. /**
  1994. * 上传机器状态之门的状态:
  1995. * type(类型,0:外门,1:内门),
  1996. * status(状态:0:关闭,1:开启)
  1997. *
  1998. * @param clientId
  1999. * @return status(状态:0:关闭,1:开启)
  2000. */
  2001. @GetMapping("/updateEquipmentStatus")
  2002. public ResponseModel<?> updateEquipmentStatus(String clientId, String type, String status) {
  2003. if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(type) || StringUtils.isEmpty(status)) {
  2004. return R.fail(ResponseCodesEnum.A0001, "adminId为空");
  2005. }
  2006. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  2007. query.eq(TEquipment::getClientId, clientId);
  2008. TEquipment equipment = equipmentService.getOnly(query);
  2009. if (equipment != null && equipment.getId() != null) {
  2010. if (type.equals("0")) {
  2011. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  2012. equipmentDesc.setOutDoor(status);
  2013. equipmentDescService.updateById(equipmentDesc);
  2014. return R.ok();
  2015. } else if (type.equals("1")) {
  2016. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  2017. equipmentDesc.setInDoor(status);
  2018. equipmentDescService.updateById(equipmentDesc);
  2019. return R.ok();
  2020. }
  2021. }
  2022. return R.fail(ResponseCodesEnum.A0002);
  2023. }
  2024. /**
  2025. * 上传花型显示状态
  2026. *
  2027. * @param clientId 设备编号
  2028. * @param tProductBean 包含花型编号和状态
  2029. * @return
  2030. */
  2031. @RequestMapping(value = "/updateShowGoods", method = RequestMethod.POST)
  2032. @ResponseBody
  2033. public String updateShowGoods(@RequestParam String clientId, @RequestBody List<TProductBean> tProductBean) {
  2034. if (StringUtils.isEmpty(clientId) || tProductBean == null) {
  2035. return "参数为空";
  2036. }
  2037. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  2038. query.eq(TEquipment::getClientId, clientId);
  2039. TEquipment equipment = equipmentService.getOnly(query);
  2040. if (equipment == null) {
  2041. return "找不到设备信息";
  2042. }
  2043. Long equipmentId = equipment.getId();
  2044. ArrayList<TProduct> tProducts = new ArrayList<>();
  2045. for (TProductBean productBean : tProductBean) {
  2046. String no = productBean.getNo();
  2047. String showType = productBean.getShowType();
  2048. LambdaQueryWrapper<TProduct> wrapper = new LambdaQueryWrapper<>();
  2049. wrapper.eq(TProduct::getEquipmentId, equipmentId);
  2050. wrapper.eq(TProduct::getNo, no);
  2051. TProduct product = productService.getOnly(wrapper);
  2052. product.setShowType(showType);
  2053. tProducts.add(product);
  2054. }
  2055. boolean res = productService.updateBatchById(tProducts);
  2056. if (!res) {
  2057. return "error";
  2058. }
  2059. return "success";
  2060. }
  2061. /**
  2062. * 上传DIY花型功能开关状态
  2063. *
  2064. * @param clientId:设备编号
  2065. * @param DIYFlowerStatus:开关状态, 0: 关闭, 1: 开启
  2066. * @return
  2067. */
  2068. @GetMapping(value = "/updateDIYFlowerStatus")
  2069. @ResponseBody
  2070. public String updateDIYFlowerStatus(String clientId, String DIYFlowerStatus) {
  2071. if (StringUtils.isNotEmpty(clientId) && StringUtils.isNotEmpty(DIYFlowerStatus)) {
  2072. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  2073. query.eq(TEquipment::getClientId, clientId);
  2074. TEquipment equipment = equipmentService.getOne(query);
  2075. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  2076. equipmentDesc.setDiyFlowerStatus(DIYFlowerStatus);
  2077. equipmentDescService.updateById(equipmentDesc);
  2078. // 如果为开启状态
  2079. if (DIYFlowerStatus.equals("1")) {
  2080. LambdaQueryWrapper<TDiyFlower> queryWrapper = Wrappers.lambdaQuery();
  2081. queryWrapper.eq(TDiyFlower::getEquipmentId, equipment.getId());
  2082. List<TDiyFlower> list = diyFlowerService.list(queryWrapper);
  2083. // 如何为空就添加新的花型形状和颜色
  2084. if (list.size() == 0) {
  2085. saveDIYProduct(equipment.getId());
  2086. }
  2087. }
  2088. return "success";
  2089. }
  2090. return "error";
  2091. }
  2092. /**
  2093. * 添加DIY花型产品
  2094. *
  2095. * @param id
  2096. */
  2097. private void saveDIYProduct(Long id) {
  2098. String[] str = {"圆五花-S01", "圆心-S02", "心-S03", "圆蝴蝶-S04", "圆四叶草-S05", "圆六花瓣-S06", "圆三叶草-A07", "圆三花瓣-S08", "蘑菇-S09",
  2099. "白糖-T01", "红糖-T02", "黄糖-T03", "蓝糖-T04"};
  2100. for (int i = 0; i < str.length; i++) {
  2101. TDiyFlower diyFlower = new TDiyFlower();
  2102. diyFlower.setCreateDate(new Date());
  2103. diyFlower.setModifyDate(new Date());
  2104. diyFlower.setEquipmentId(id);
  2105. String[] split = str[i].split("-");
  2106. diyFlower.setName(split[0]);
  2107. diyFlower.setNo(split[1]);
  2108. diyFlower.setShowType("1");
  2109. diyFlowerService.save(diyFlower);
  2110. }
  2111. }
  2112. /**
  2113. * 上传DIY花型形状/糖显示状态
  2114. *
  2115. * @param clientId 设备编号
  2116. * @param tProductBean 包含形状/糖的编号和状态
  2117. * @return
  2118. */
  2119. @RequestMapping(value = "/updateDIYFlowerShow", method = RequestMethod.POST)
  2120. @ResponseBody
  2121. public String updateDIYFlowerShow(@RequestParam String clientId, @RequestBody List<TProductBean> tProductBean) {
  2122. if (StringUtils.isEmpty(clientId) || tProductBean == null) {
  2123. return "参数为空";
  2124. }
  2125. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  2126. query.eq(TEquipment::getClientId, clientId);
  2127. TEquipment equipment = equipmentService.getOnly(query);
  2128. if (equipment == null) {
  2129. return "找不到设备信息";
  2130. }
  2131. Long equipmentId = equipment.getId();
  2132. ArrayList<TDiyFlower> diyFlowers = new ArrayList<>();
  2133. for (TProductBean productBean : tProductBean) {
  2134. String no = productBean.getNo();
  2135. String showType = productBean.getShowType();
  2136. LambdaQueryWrapper<TDiyFlower> wrapper = new LambdaQueryWrapper<>();
  2137. wrapper.eq(TDiyFlower::getEquipmentId, equipmentId);
  2138. wrapper.eq(TDiyFlower::getNo, no);
  2139. TDiyFlower diyFlower = diyFlowerService.getOne(wrapper);
  2140. diyFlower.setShowType(showType);
  2141. diyFlowers.add(diyFlower);
  2142. }
  2143. boolean res = diyFlowerService.updateBatchById(diyFlowers);
  2144. if (!res) {
  2145. return "error";
  2146. }
  2147. return "success";
  2148. }
  2149. /**
  2150. * 花型数目 开机时上传
  2151. *
  2152. * @param clientId 个推
  2153. * @return
  2154. */
  2155. @RequestMapping(value = "/flowerNumber", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  2156. @ResponseBody
  2157. public String flowerNumber(String clientId, String flowerNumber) {
  2158. if (!StringUtils.isEmpty(flowerNumber)) {
  2159. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  2160. query.eq(TEquipment::getClientId, clientId);
  2161. TEquipment equipment = equipmentService.getOne(query);
  2162. equipment.setFlowers(flowerNumber);
  2163. equipmentService.updateById(equipment);
  2164. return "success";
  2165. }
  2166. return "fail";
  2167. }
  2168. /**
  2169. * 设备语言 开机时上传
  2170. *
  2171. * @param clientId 个推
  2172. * @return
  2173. */
  2174. @RequestMapping(value = "/upLoadLanguage", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  2175. @ResponseBody
  2176. public String upLoadLanguage(String clientId, String language) {
  2177. if (!StringUtils.isEmpty(language)) {
  2178. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  2179. query.eq(TEquipment::getClientId, clientId);
  2180. TEquipment equipment = equipmentService.getOne(query);
  2181. if (equipment == null) {
  2182. return "fail";
  2183. }
  2184. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  2185. equipmentDesc.setLanguage(language);
  2186. equipmentDescService.updateById(equipmentDesc);
  2187. LambdaQueryWrapper<TProduct> wrapper = Wrappers.lambdaQuery();
  2188. wrapper.eq(TProduct::getEquipmentId, equipment.getId());
  2189. List<TProduct> products = productService.list(wrapper);
  2190. for (TProduct product : products) {
  2191. String no = product.getNo();
  2192. // 如果没改过名才更改
  2193. if (StringUtils.isEmpty(product.getName())) {
  2194. LambdaQueryWrapper<TNameDictionary> lambdaQueryWrapper = Wrappers.lambdaQuery();
  2195. lambdaQueryWrapper.eq(TNameDictionary::getLanguage, language);
  2196. lambdaQueryWrapper.eq(TNameDictionary::getNo, no);
  2197. TNameDictionary nameDictionary = nameDictionaryService.getOne(lambdaQueryWrapper);
  2198. if (nameDictionary != null) {
  2199. product.setModifyDate(new Date());
  2200. product.setProductName(nameDictionary.getName());
  2201. productService.updateById(product);
  2202. }
  2203. }
  2204. }
  2205. // if (equipmentDesc.getLanguage() == null || !(equipmentDesc.getLanguage().equals(language))) {
  2206. // }
  2207. return "success";
  2208. }
  2209. return "fail";
  2210. }
  2211. /**
  2212. * 获取DIY使用密码
  2213. * @return
  2214. */
  2215. @RequestMapping(value = "/getDIYPassword", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  2216. @ResponseBody
  2217. public String getDIYPassword() {
  2218. TAdmin admin = adminService.getById(1L);
  2219. String diyPassword = admin.getDiyPassword();
  2220. return diyPassword;
  2221. }
  2222. }