IndexController.java 93 KB

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