12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039 |
- package com.szwl.controller;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.szwl.constant.ResponseCodesEnum;
- import com.szwl.model.bean.*;
- import com.szwl.model.bo.JsonUtils;
- import com.szwl.model.bo.R;
- import com.szwl.model.bo.ResponseModel;
- import com.szwl.model.entity.*;
- import com.szwl.model.utils.AdminUtils;
- import com.szwl.model.utils.HttpClientSslUtils;
- import com.szwl.model.utils.PushUtils;
- import com.szwl.service.*;
- import com.szwl.service.es.EsTEquipmentService;
- import com.szwl.util.IDGenerator;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.io.IOUtils;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.amqp.core.AmqpAdmin;
- import org.springframework.amqp.core.Binding;
- import org.springframework.amqp.core.Queue;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.*;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- @Api(value = "/indexController", tags = {"设备信息上传接口"})
- @RestController
- @RequestMapping("/api/app_equipment/index")
- public class IndexController { ;
- @Autowired
- TAdminService adminService;
- @Autowired
- TEquipmentService equipmentService;
- @Autowired
- TEquipmentApplyService equipmentApplyService;
- @Autowired
- TProductService productService;
- @Autowired
- TProportionService proportionService;
- @Autowired
- TEquipmentDescService equipmentDescService;
- @Autowired
- EsTEquipmentService esTEquipmentService;
- @Autowired
- TParametersService parametersService;
- @Autowired
- TPriceService priceService;
- @Autowired
- TPromoCodeService promoCodeService;
- @Autowired
- private AmqpAdmin amqpAdmin;
- @ApiOperation(value = "心跳")
- // @PostMapping("/heart.htm")
- @RequestMapping(value = "/heart.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String heart(@RequestBody EquipmentVo equipmentVo) {
- String clientId = equipmentVo.getClientId();
- Date lastUpdateTime = equipmentVo.getLastUpdateTime();
- Double longitude = equipmentVo.getLongitude();
- Double latitude = equipmentVo.getLatitude();
- String cabinetHd = equipmentVo.getCabinetHd();
- String cabinetTm = equipmentVo.getCabinetTm();
- String furnaceSp = equipmentVo.getFurnaceSp();
- String furnaceTm = equipmentVo.getFurnaceTm();
- String gtClientId = equipmentVo.getGtClientId();
- String volume = equipmentVo.getVolume();
- Integer eqeStatus = equipmentVo.getEqeStatus();
- Boolean is_sleep = equipmentVo.getIs_sleep();
- String netWorkingMode = equipmentVo.getNetWorkingMode();
- String numberOne = equipmentVo.getNumberOne();
- String candyGeneratorTm = equipmentVo.getCandyGeneratorTm();
- String outsideTm = equipmentVo.getOutsideTm();
- String outsideHd = equipmentVo.getOutsideHd();
- //有记录,则进行修改
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment _new = equipmentService.getOne(query);
- if (_new != null) {
- _new.setNetWorkingMode(netWorkingMode);
- if(StringUtils.isNotEmpty(cabinetTm)){
- _new.setCabinetTm(cabinetTm);
- }
- if(StringUtils.isNotEmpty(cabinetHd)){
- _new.setCabinetHd(cabinetHd);
- }
- if(StringUtils.isNotEmpty(furnaceSp)){
- _new.setFurnaceSp(furnaceSp);
- }
- if(StringUtils.isNotEmpty(furnaceTm)){
- _new.setFurnaceTm(furnaceTm);
- }
- _new.setLastUpdateTime(lastUpdateTime);
- // _new.setLongitude(longitude);
- if(eqeStatus!=null){
- _new.setEqeStatus(eqeStatus);
- }
- if(is_sleep!=null){
- _new.setIsSleep(is_sleep);
- }
- if(!StringUtils.isEmpty(furnaceTm)){
- int fur = Integer.parseInt(furnaceTm);
- if(_new.getEqeStatus()==0&&fur>150){
- _new.setEqeStatus(1);
- }
- if(_new.getEqeStatus()==null&&fur>150){
- _new.setEqeStatus(1);
- }
- }
- if(!StringUtils.isEmpty(volume)){
- _new.setVolume(volume);
- }
- // _new.setLatitude(latitude);
- _new.setGtClientId(gtClientId);
- _new.setModifyDate(new Date());
- equipmentService.updateById(_new);
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(_new.getId());
- if(StringUtils.isNotEmpty(equipmentVo.getBlueSugar())){
- equipmentDesc.setBlueSugar(equipmentVo.getBlueSugar());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getRedSugar())){
- equipmentDesc.setRedSugar(equipmentVo.getRedSugar());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getYellowSugar())){
- equipmentDesc.setYellowSugar(equipmentVo.getYellowSugar());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getWhiteSugar())){
- equipmentDesc.setWhiteSugar(equipmentVo.getWhiteSugar());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getWater())){
- equipmentDesc.setWater(equipmentVo.getWater());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getWasteWater())){
- equipmentDesc.setWasteWater(equipmentVo.getWasteWater());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getStick())){
- equipmentDesc.setStick(equipmentVo.getStick());
- }
- if(equipmentVo.getCupQuantity() != null){
- equipmentDesc.setCupQuantity(equipmentVo.getCupQuantity());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getStirTm())){
- equipmentDesc.setStirTm(equipmentVo.getStirTm());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getCornGeneratorTm())){
- equipmentDesc.setCornGeneratorTm(equipmentVo.getCornGeneratorTm());
- }
- if(StringUtils.isNotEmpty(numberOne)){
- equipmentDesc.setNumberOne(numberOne);
- }
- if(StringUtils.isNotEmpty(candyGeneratorTm)){
- equipmentDesc.setCandyGeneratorTm(candyGeneratorTm);
- }
- if(StringUtils.isNotEmpty(outsideHd)){
- equipmentDesc.setOutsideHd(outsideHd);
- }
- if(StringUtils.isNotEmpty(outsideTm)){
- equipmentDesc.setOutsideTm(outsideTm);
- }
- equipmentDescService.updateById(equipmentDesc);
- // return JsonMessage.success("心跳成功");
- return "心跳成功";
- }
- // return JsonMessage.error("心跳失败");
- return "心跳失败";
- }
- /**
- * 设备申请
- *
- * @param clientId 个推
- * @param managerId 管理系统id
- * @return
- */
- @ApiOperation(value = "设备申请")
- @RequestMapping(value = "/initNew.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String initNew(String clientId, String managerId, String gtClientId, String equimentType) {
- String machineType = "0";
- String status = "0";
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.like(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- if (list.size() > 0) {
- TEquipment equipment = list.get(0);
- if(equipment.getAdminId()!=31){
- if(!equipment.getClientId().substring(equipment.getClientId().length()-3,equipment.getClientId().length()).equals("xxx")){
- String managerId1 = equipment.getManagerId();
- if(!managerId.equals(managerId1)){
- return "该设备未脱离";
- }else {
- return "该设备已经初始化";
- }
- }
- }else {
- status = "1";
- }
- }
- if (StringUtils.isEmpty(gtClientId)) {
- return "设备不能为空";
- }
- LambdaQueryWrapper<TEquipmentApply> query1 = Wrappers.lambdaQuery();
- query1.eq(TEquipmentApply::getClientId,clientId);
- query1.eq(TEquipmentApply::getStatusType,"1");
- query1.eq(TEquipmentApply::getManagerId,managerId);
- String dateStr = "2022-12-28 00:00:00";
- //获得SimpleDateFormat类,我们转换为yyyy-MM-dd的时间格式
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- //使用SimpleDateFormat的parse()方法生成Date
- Date date = sf.parse(dateStr);
- query1.gt(TEquipmentApply::getCreateDate,date);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- List<TEquipmentApply> list1 = equipmentApplyService.list(query1);
- if(list1.size()>0){
- return "重复申请";
- }
- TEquipmentApply equipmentApply = new TEquipmentApply();
- equipmentApply.setStatusType(1);
- equipmentApply.setClientId(clientId);
- equipmentApply.setManagerId(managerId);
- equipmentApply.setGtClientId(gtClientId);
- Long adminId = AdminUtils.decrypt(false, managerId);
- TAdmin admin = adminService.getById(adminId);
- if (admin == null) {
- return "找不到商家";
- }
- //所属商家
- String username = admin.getUsername();
- equipmentApply.setAdminId(adminId);
- equipmentApply.setAdminUserName(username);
- equipmentApply.setEquimentType(equimentType);
- if(equimentType.equals("POP320")) {
- machineType = "1";
- }
- equipmentApply.setMachineType(machineType);
- equipmentApply.setCreateDate(new Date());
- equipmentApply.setModifyDate(new Date());
- equipmentApplyService.save(equipmentApply);
- if(status.equals("1")||String.valueOf(adminId).equals("3")||String.valueOf(adminId).equals("31")||String.valueOf(adminId).equals("506")||String.valueOf(adminId).equals("1090")){
- Long id = equipmentApply.getId();
- agree(id);
- return "设备申请成功";
- }
- if(admin.getApplyStartTime()!=null&&admin.getApplyEndTime()!=null){
- Date applyStartTime = admin.getApplyStartTime();
- Date applyEndTime = admin.getApplyEndTime();
- Date now = new Date();
- if(now.getTime()>applyStartTime.getTime()&&now.getTime()<applyEndTime.getTime()){
- Long id = equipmentApply.getId();
- agree(id);
- return "设备申请成功";
- }
- }
- return "设备申请中,请耐心等待";
- }
- private void agree(Long id) {
- String status = "agreed";
- if (null != id) {
- TEquipmentApply equipmentApply = equipmentApplyService.getById(id);
- Integer statusType = equipmentApply.getStatusType();
- if(statusType>1){
- equipmentApply = null;
- }
- if (equipmentApply != null) {
- if (!StringUtils.isEmpty(status)) {
- if (status.equals("agreed")) {
- String clientId = equipmentApply.getClientId();
- //判断是否设备初始化
- Long adminId = equipmentApply.getAdminId();
- String adminLevel = equipmentApply.getAdminLevel();
- String adminUserName = equipmentApply.getAdminUserName();
- String gtClientId = equipmentApply.getGtClientId();
- String equimentType = equipmentApply.getEquimentType();
- String machineType = equipmentApply.getMachineType();
- TAdmin admin = adminService.getById(adminId);
- String companyType = admin.getCompanyType(); // 公司平台
- String old = "";
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.like(TEquipment::getClientId,clientId+"xxx");
- List<TEquipment> list = equipmentService.list(query);
- LambdaQueryWrapper<TEquipment> query0 = Wrappers.lambdaQuery();
- query0.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list2 = equipmentService.list(query0);
- equipmentApply.setStatusType(3);
- if (list.size() > 0||list2.size()>0) {
- //表示设备第二次申请了:主要为了区分脱离以及初始化
- old = "1";
- //重新修改设备名称
- TEquipment equipment = new TEquipment();
- if(list2.size()>0){
- equipment = list2.get(0);
- }else {
- equipment = list.get(0);
- }
- equipment.setId(IDGenerator.commonID());
- equipment.setClientId(clientId);
- equipment.setGtClientId(gtClientId);
- equipment.setAdminId(adminId);
- equipment.setAdminLevel(adminLevel);
- equipment.setAdminUserName(adminUserName);
- equipment.setMachineType(machineType);
- equipment.setCompanyType(companyType);
- if(equipmentApply.getEquimentType().equals("MG320-1")){
- if(!equipmentApply.getEquimentType().equals(equipment.getEquimentType())&&equipment.getEquimentType().equals("MG320")){
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- List<TProduct> productList = productService.list(queryProduct);
- if(productList.size()==18){
- //从18种变成30种花型
- saveProductMG12(equipment.getId());
- }
- //从18种变成30种花型
- // saveProductMG12(equipment.getId());
- }
- equipment.setEquimentType("MG320");
- }
- if(equipmentApply.getEquimentType().equals("MG330")){
- equipment.setEquimentType("MG330");
- }
- if(equipmentApply.getEquimentType().equals("POP320")) {
- equipment.setEquimentType(equipmentApply.getEquimentType());
- }
- equipmentService.updateById(equipment);
- LambdaQueryWrapper<TProportion> queryProportion = Wrappers.lambdaQuery();
- queryProportion.eq(TProportion::getEquipmentId,equipment.getId());
- List<TProportion> list1 = proportionService.list(queryProportion);
- if(list1.size()>0){
- for(TProportion proportion:list1){
- proportionService.removeById(proportion.getId());
- }
- }
- // if(String.valueOf(adminId).equals("3")||String.valueOf(adminId).equals("31")||String.valueOf(adminId).equals("506")||String.valueOf(adminId).equals("1090")){
- // //自动设置分销
- // setProportion(adminId,equipment.getId(),clientId);
- // }
- try {
- esTEquipmentService.updateDataById(equipment);
- }catch (Exception e) {
- e.printStackTrace();
- }
- if(StringUtils.isEmpty(machineType) || machineType.equals("0")) {
- equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
- } else {
- equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "【爆米花】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
- }
- if(equipment.getEquimentType().equals("280")){
- equipmentService.sentMessage(clientId,PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
- }
- }else{
- TEquipment equipment = new TEquipment();
- equipment.setId(IDGenerator.commonID());
- equipment.setCreateDate(new Date());
- equipment.setModifyDate(new Date());
- equipment.setClientId(clientId);
- equipment.setManagerId(equipmentApply.getManagerId());
- equipment.setAdminId(adminId);
- equipment.setAdminLevel(adminLevel);
- equipment.setGtClientId(gtClientId);
- equipment.setAdminUserName(adminUserName);
- equipment.setIsUsing(true);
- equipment.setIsNetWork(true);
- equipment.setGuestPwd("123456");
- equipment.setAdminPwd("123456");
- equipment.setChannel("1");
- equipment.setProductTotal(0);
- equipment.setCompanyType(companyType);
- //设置默认规则
- equipment.setTimeRuleId(Long.valueOf(1));
- if(equimentType.equals("MG320-1")){
- equipment.setEquimentType("MG320");
- }else {
- equipment.setEquimentType(equimentType);
- }
- // if(equimentType.equals("MG330")){
- // equipment.setEquipmentType("MG330");
- // }
- // if(equimentType.equals("POP320")){
- // equipment.setEquipmentType(equipmentType);
- // }
- if(!StringUtils.isEmpty(equimentType)&&equimentType.equals("MG280")){
- Long monthBegin = getMonthBegin(new Date());
- long time = System.currentTimeMillis();
- if(time<monthBegin){
- equipment.setEndDate(new Date(monthBegin));
- }else{
- Date date = nextMonthDate();
- equipment.setEndDate(date);
- }
- equipmentService.sentMessage(clientId,PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
- }
- equipmentService.save(equipment);
- if(StringUtils.isEmpty(machineType) || machineType.equals("0")) {
- equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
- } else {
- equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "【爆米花】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
- }
- // Equipment byClientId = equipmentService.findByClientId(equipment.getClientId());
- // String data = com.alibaba.fastjson.JSON.toJSONString(byClientId);
- LambdaQueryWrapper<TEquipment> query3 = Wrappers.lambdaQuery();
- query3.eq(TEquipment::getClientId,clientId);
- TEquipment tEquipment = equipmentService.getOne(query3);
- // List<TEquipment> list1 = equipmentService.list(query3);
- try {
- // if(list1.size()>0){
- // TEquipment tEquipment = list1.get(0);
- // esTEquipmentService.insertData(tEquipment);
- // }
- if(tEquipment != null) {
- esTEquipmentService.insertData(tEquipment);
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- TEquipmentDesc equipmentDesc = new TEquipmentDesc();
- equipmentDesc.setEquipmentId(tEquipment.getId());
- equipmentDescService.save(equipmentDesc);
- }
- //获取设备的id
- // Long equipmentId = equipmentService.findByClientId(clientId).getId();
- LambdaQueryWrapper<TEquipment> query1 = Wrappers.lambdaQuery();
- query1.eq(TEquipment::getClientId,clientId);
- // List<TEquipment> list1 = equipmentService.list(query1);
- TEquipment equipment = equipmentService.getOne(query1);
- Long equipmentId = equipment.getId();
- // if (!productService.exists(Filter.eq("equipmentId", equipmentId))) {
- if(StringUtils.isEmpty(machineType) || machineType.equals("0")) {
- if(equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG280")){
- saveProductMG280(equipmentId);
- } else if (equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG320-1")){
- saveProductMG1(equipmentId);
- } else{
- saveProduct(equipmentId);
- }
- } else {
- if(equimentType.equals("POP320")) {
- saveProductPOP320(equipmentId);
- }
- }
- if(String.valueOf(adminId).equals("3")||String.valueOf(adminId).equals("31")||String.valueOf(adminId).equals("506")||String.valueOf(adminId).equals("1090")){
- //自动设置分销
- setProportion(adminId,equipmentId,clientId);
- }
- } else if (status.equals("rejected")) {
- equipmentApply.setStatusType(2);
- equipmentService.sentMessage(equipmentApply.getClientId(),PushUtils.buildJson("statusType", "rejected").toString());
- // PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "拒绝", PushUtils.buildJson("statusType", "rejected").toString());
- }
- equipmentApplyService.updateById(equipmentApply);
- }
- }
- }
- }
- private void setProportion(Long adminId,Long equipmentId,String clientId) {
- //先找到原账户的分销
- LambdaQueryWrapper<TProportion> query3 = Wrappers.lambdaQuery();
- query3.eq(TProportion::getAdminId,adminId);
- List<TProportion> list3 = proportionService.list(query3);
- if(list3.size()>0){
- TProportion adminProportion = list3.get(0);
- if(StringUtils.isEmpty(adminProportion.getClientId())){
- TProportion equipmentProportion = new TProportion();
- equipmentProportion.setCreateDate(new Date());
- equipmentProportion.setModifyDate(new Date());
- equipmentProportion.setAdminId(adminId);
- equipmentProportion.setClientId(clientId);
- equipmentProportion.setEquipmentId(equipmentId);
- equipmentProportion.setAdminProportion(adminProportion.getAdminProportion());
- Integer type = adminProportion.getType();
- if(type!=null){
- switch (type) {
- case 1:
- equipmentProportion.setProportion(adminProportion.getAgencyProportion());
- equipmentProportion.setAgencyProportion(new BigDecimal("0.00"));
- equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(0);
- break;
- case 2:
- equipmentProportion.setProportion(adminProportion.getMerchantProportion());
- equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
- // if(adminProportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))!=0){
- // equipmentProportion.setAgencyId(admin.getAgencyId());
- // TAdmin byId = adminService.getById(admin.getAgencyId());
- // equipmentProportion.setAgencyName(byId.getUsername());
- // }
- equipmentProportion.setAgencyId(adminProportion.getAgencyId());
- TAdmin byId = adminService.getById(adminProportion.getAgencyId());
- equipmentProportion.setAgencyName(byId.getUsername());
- equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(1);
- break;
- case 3:
- equipmentProportion.setProportion(adminProportion.getPersonageProportion());
- equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
- // if(adminProportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))!=0){
- // equipmentProportion.setAgencyId(admin.getAgencyId());
- // TAdmin byId = adminService.getById(admin.getAgencyId());
- // equipmentProportion.setAgencyName(byId.getUsername());
- // }
- equipmentProportion.setAgencyId(adminProportion.getAgencyId());
- TAdmin byId1 = adminService.getById(adminProportion.getAgencyId());
- equipmentProportion.setAgencyName(byId1.getUsername());
- equipmentProportion.setMerchantProportion(adminProportion.getMerchantProportion());
- // if(adminProportion.getMerchantProportion().compareTo(new BigDecimal("0.00"))!=0){
- // equipmentProportion.setMerchantId(admin.getMerchantId());
- // TAdmin byId = adminService.getById(admin.getMerchantId());
- // equipmentProportion.setMerchantName(byId.getUsername());
- // }
- equipmentProportion.setMerchantId(adminProportion.getMerchantId());
- TAdmin byId2 = adminService.getById(adminProportion.getMerchantId());
- equipmentProportion.setMerchantName(byId2.getUsername());
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(2);
- break;
- }
- boolean save = proportionService.save(equipmentProportion);
- }
- }
- }
- }
- /**
- * 添加棉花糖产品
- * @param id
- */
- private void saveProduct(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
- "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG280(Long id) {
- String[] str = { "水中芙蓉-A05", "水中芙蓉mini-A31", "烈焰红唇-A06", "烈焰红唇mini-A32", "夏日爱恋-A11", "夏日爱恋mini-A33", "冰美人-A12", "冰美人mini-A34", "彩色精灵-A17", "彩色精灵mini-A35"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG1(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09",
- "心之守护-A10", "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18",
- "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24","坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28",
- "花样年华-A29","心花怒放-A30"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG12(Long id) {
- String[] str = { "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24"
- ,"坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28","花样年华-A29","心花怒放-A30"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setEquipmentId(id);
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG22(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
- "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19","蜂缠蝶恋-A22","坠入星空-A25","花飞蝶舞-A28"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG26(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
- "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19","蜂缠蝶恋-A22","坠入星空-A25","花飞蝶舞-A28",
- "夏日倾城-A20", "雪花飞舞-A26", "豆蔻年华-A23", "花样年华-A29"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG42(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09",
- "心之守护-A10", "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18",
- "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24","坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28",
- "花样年华-A29","心花怒放-A30","花好月圆-A37","出水芙蓉-A38","微光染晕-A39","夏日莓莓-A40","芳楚纷飞-A41","晨夕光晕-A42","坠入爱河-A43","天马行空-A44",
- "灼灼其华-A45","一帘幽梦-A46","七月初夏-A47","四月微风-A48"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- /**
- * 添加爆米花产品
- * @param id
- */
- private void saveProductPOP320(Long id) {
- String[] str = {"活力爆米花(正常糖)-B01", "活力爆米花(无糖)-B02", "活力爆米花(巧克力)-B03", "活力爆米花(焦糖)-B04", "活力爆米花(水蜜桃)-B05", "活力爆米花(蓝莓)-B06"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- /**
- * 获取指定日期所在月份开始的时间戳
- * @param date 指定日期
- * @return
- */
- public static Long getMonthBegin(Date date) {
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- //设置为10号,当前日期既为本月10号
- c.set(Calendar.DAY_OF_MONTH, 10);
- //将小时至0
- c.set(Calendar.HOUR_OF_DAY, 0);
- //将分钟至0
- c.set(Calendar.MINUTE, 0);
- //将秒至0
- c.set(Calendar.SECOND,0);
- //将毫秒至0
- c.set(Calendar.MILLISECOND, 0);
- // 获取本月第一天的时间戳
- return c.getTimeInMillis();
- }
- public static Date nextMonthDate() {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.DAY_OF_MONTH,10);
- //将小时至0
- calendar.set(Calendar.HOUR_OF_DAY, 0);
- //将分钟至0
- calendar.set(Calendar.MINUTE, 0);
- //将秒至0
- calendar.set(Calendar.SECOND,0);
- //将毫秒至0
- calendar.set(Calendar.MILLISECOND, 0);
- calendar.add(Calendar.MONTH,1);
- return calendar.getTime();
- }
- /**
- *改花型
- * @param
- * @return
- */
- @RequestMapping(value = "/updateFlowers.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateFlowers(String clientId,String number){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if(equipment!=null){
- Long id = equipment.getId();
- //修改花型记录数目
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(id);
- if(equipmentDesc!=null){
- equipmentDesc.setFlowers(number);
- equipmentDescService.updateById(equipmentDesc);
- }else {
- TEquipmentDesc equipmentDesc1 = new TEquipmentDesc();
- equipmentDesc1.setEquipmentId(id);
- equipmentDesc1.setFlowers(number);
- equipmentDescService.save(equipmentDesc1);
- }
- //删除旧花型
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- List<TProduct> productList = productService.list(queryProduct);
- for(TProduct product : productList){
- productService.removeById(product.getId());
- }
- //创建花型
- if(number.equals("18")){
- saveProduct(id);
- }
- if(number.equals("22")){
- saveProductMG22(id);
- }
- if(number.equals("26")){
- saveProductMG26(id);
- }
- if(number.equals("30")){
- saveProductMG1(id);
- }
- if(number.equals("42")) {
- saveProductMG42(id);
- }
- return "success";
- }else {
- return "error";
- }
- }
- /**
- * 设备类型 开机时上传
- *
- * @param clientId 个推
- * @return
- */
- @RequestMapping(value = "/equimentType.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String equimentType(String clientId, String equimentType){
- if(!StringUtils.isEmpty(equimentType)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- equipment.setEquimentType(equimentType);
- equipmentService.updateById(equipment);
- }
- // return JsonMessage.success("success");
- return "success";
- }
- /**
- * 设备地址 开机时上传
- * @param clientId 个推
- * @return
- */
- @RequestMapping(value = "/equimentArea.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String equimentArea(String clientId, String longitude, String latitude, String fullName){
- if(!StringUtils.isEmpty(longitude)&&!StringUtils.isEmpty(latitude)&&!StringUtils.isEmpty(fullName)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- equipment.setLatitude(Double.valueOf(latitude));
- equipment.setLongitude(Double.valueOf(longitude));
- equipment.setFullName(fullName+"-");
- equipmentService.updateById(equipment);
- // return JsonMessage.success("success");
- return "success";
- }
- // return JsonMessage.success("error");
- return "error";
- }
- /**
- * 商品调价
- */
- @RequestMapping(value = "/updateProduct.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateProduct(@RequestBody List<ProductVo> productVos) {
- Double f=0.00;
- int num=0;
- int n=0;
- HashSet<Double> price = new HashSet<Double>();
- HashSet<Double> minprice = new HashSet<Double>();
- for (ProductVo product : productVos) {
- String clientId = product.getClientId();
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- Long id = equipment.getId();
- if(StringUtils.isNotEmpty(product.getShowType())){
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- queryProduct.eq(TProduct::getProductName,product.getProductName());
- List<TProduct> productList = productService.list(queryProduct);
- TProduct tProduct = productList.get(0);
- tProduct.setRmbPrice(BigDecimal.valueOf(product.getRmbPrice()));
- tProduct.setCodePrice(BigDecimal.valueOf(product.getCodePrice()));
- tProduct.setShowType(product.getShowType());
- tProduct.setSellStatus(product.getSellStatus());
- productService.updateById(tProduct);
- }else {
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- queryProduct.eq(TProduct::getProductName,product.getProductName());
- List<TProduct> productList = productService.list(queryProduct);
- TProduct tProduct = productList.get(0);
- tProduct.setRmbPrice(BigDecimal.valueOf(product.getRmbPrice()));
- tProduct.setCodePrice(BigDecimal.valueOf(product.getCodePrice()));
- tProduct.setSellStatus(product.getSellStatus());
- productService.updateById(tProduct);
- }
- }
- return "调价成功";
- }
- public Double tran(Double d){
- return new BigDecimal(d).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
- }
- public Double tran2(Double d){
- return new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
- }
- /**
- * 密码修改
- *
- * @param clientId 设备个推Id
- * @param pwdType 密码类型 1d代表修adminPwd,0代表guestPwd
- * @return
- * @Param pwd 密码内容
- */
- @RequestMapping(value = "/updatePwd.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updatePwd(String clientId, String pwdType, String pwd) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment != null) {
- if (!StringUtils.isEmpty(pwdType)) {
- switch (pwdType) {
- case "1":
- equipment.setAdminPwd(pwd);
- break;
- case "0":
- equipment.setGuestPwd(pwd);
- break;
- }
- equipmentService.updateById(equipment);
- // return JsonMessage.success("更新密码成功");
- return "更新密码成功";
- }
- }
- // return JsonMessage.error("更新密码失败");
- return "更新密码失败";
- }
- /**
- * 设备获取密码
- */
- @GetMapping(value = "/getPwd", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getPwd(String clientId) {
- if(StringUtils.isEmpty(clientId)){
- return null;
- }
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- Map<String,String> map = new HashMap<>();
- map.put("adminPwd",equipment.getAdminPwd());
- map.put("guestPwd",equipment.getGuestPwd());
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("code", 0);
- jsonObject.put("data", JSONObject.toJSON(map).toString());
- jsonObject.put("errmsg", "");
- return jsonObject.toJSONString();
- }
- /**
- * 修改支付方式
- *
- * @param clientId
- * @param payType: 无需支付
- * 线上支付
- * 线下支付
- * 线上/线下
- * @return
- */
- @RequestMapping(value = "/updatePayType.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updatePayType(String clientId, String payType) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "修改支付方式失败";
- }
- equipment.setPayType(0);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 日志上传
- */
- @RequestMapping(value = "/sendLog.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String uploadFile(HttpServletRequest request, HttpServletResponse response, String fileName) throws Exception{
- String fileFullPath = "/home/hboxs/log/" + fileName+".txt";
- // String fileFullPath = "/root/uploadfile/apache-tomcat-8.5.42/" + fileName;
- InputStream input = null;
- FileOutputStream fos = null;
- try {
- input = request.getInputStream();
- File file = new File("/home/hboxs/log/");
- if(!file.exists()){
- file.mkdirs();
- }
- fos = new FileOutputStream(fileFullPath);
- int size = 0;
- byte[] buffer = new byte[1024];
- while ((size = input.read(buffer,0,1024)) != -1) {
- fos.write(buffer, 0, size);
- }
- //响应信息 json字符串格式
- Map<String,Object> responseMap = new HashMap<String,Object>();
- responseMap.put("flag", true);
- //生成响应的json字符串
- String jsonResponse = JSONObject.toJSONString(responseMap);
- sendResponse(jsonResponse,response);
- } catch (IOException e) {
- //响应信息 json字符串格式
- Map<String,Object> responseMap = new HashMap<String,Object>();
- responseMap.put("flag", false);
- responseMap.put("errorMsg", e.getMessage());
- String jsonResponse = JSONObject.toJSONString(responseMap);
- sendResponse(jsonResponse,response);
- } finally{
- if(input != null){
- input.close();
- }
- if(fos != null){
- fos.close();
- }
- }
- return null;
- }
- /**
- * 返回响应
- *
- * @throws Exception
- */
- private void sendResponse(String responseString,HttpServletResponse response) throws Exception {
- response.setContentType("application/json;charset=UTF-8");
- PrintWriter pw = null;
- try {
- pw = response.getWriter();
- pw.write(responseString);
- pw.flush();
- } finally {
- IOUtils.closeQuietly(pw);
- }
- }
- /**
- * 脱离系统
- *
- * @param clientId
- * @return
- */
- @RequestMapping(value = "/separate.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String separate(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipmentService.sentMessage(clientId,PushUtils.buildJson("tuoji", "0").toString());
- if("xxx".equals(equipment.getClientId().substring(equipment.getClientId().length()-3,equipment.getClientId().length()))){
- return "脱离成功";
- }
- equipment.setClientId(equipment.getClientId() + "xxx");
- equipmentService.updateById(equipment);
- return "脱离成功";
- }
- /**
- * 脱离系统
- *
- * @param clientId
- * @return
- */
- @RequestMapping(value = "/updateClientId", method = RequestMethod.POST)
- @ResponseBody
- public String updateClientId(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- if("xxx".equals(equipment.getClientId().substring(equipment.getClientId().length()-3,equipment.getClientId().length()))){
- return "脱离成功";
- }
- equipment.setClientId(equipment.getClientId() + "xxx");
- equipment.setManagerId(null);
- equipmentService.updateById(equipment);
- return "脱离成功";
- }
- /**
- * 修改设备联系人名称以及电话
- */
- @RequestMapping(value = "/updateContractPN.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateContractPN(String clientId, String contactName, String contactPhone) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipment.setContactName(contactName);
- equipment.setContactPhone(contactPhone);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 设备上传公司电话
- */
- @RequestMapping(value = "/sentCompanyPhone.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String sentCompanyPhone(String clientId, String companyPhone) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipment.setCompanyPhone(companyPhone);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 获取二维码图片
- */
- @RequestMapping(value = "/getQrCodeImgUrl.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getQrCodeImgUrl(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "404";
- }
- return "400";
- }
- /**
- * 上传4G卡号
- */
- @RequestMapping(value = "/sentSimNo.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String sentSimNo(String clientId, String simNo) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- // return JsonMessage.error("该设备不存在");
- return "该设备不存在";
- }
- equipment.setSimNo(simNo);
- equipmentService.updateById(equipment);
- // return JsonMessage.success("修改成功");
- return "修改成功";
- }
- /**
- * 上传机器的apk版本
- */
- @RequestMapping(value = "/sendApkVersion.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String sendApkVersion(String clientId, String apkVersion) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipment.setApkVersion(apkVersion);
- equipmentService.updateById(equipment);
- return "success";
- }
- /**
- * 上传机器的做糖状态
- */
- @RequestMapping(value = "/equipmentStatus.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String equipmentStatus(String clientId, String status) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- //机器状态;0:空闲,1:在做糖;
- equipmentDesc.setStatus(status);
- equipmentDescService.updateById(equipmentDesc);
- return "success";
- }
- /**
- * 修改设备状态
- *
- * @param clientId
- * @param eqeStatus 设备状态1开 0关
- * @return
- */
- @RequestMapping(value = "/updateEqeStatus.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateEqeStatus(String clientId, Integer eqeStatus) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- if(eqeStatus!=null){
- equipment.setEqeStatus(eqeStatus);
- equipment.setModifyDate(new Date());
- equipmentService.updateById(equipment);
- }
- return "修改成功";
- }
- /**
- * 新修改设备状态
- *
- * @param clientId
- * @param eqeStatus 设备状态1开 0关
- * @return
- */
- @RequestMapping(value = "/updateEqeStatusNew.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateEqeStatusNew(String clientId, Integer eqeStatus,String netTime) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- // return JsonMessage.error("该设备不存在");
- return "该设备不存在";
- }
- if(eqeStatus!=null){
- equipment.setNetwork(netTime);
- equipment.setEqeStatus(eqeStatus);
- equipmentService.updateById(equipment);
- }
- // return JsonMessage.success("修改成功");
- return "修改成功";
- }
- /**
- * 修改设备锁定状态
- *
- * @param clientId
- * @param block
- * @return
- */
- @RequestMapping(value = "/updateBlock.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateBlock(String clientId, Boolean block) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- // return JsonMessage.error("该设备不存在");
- return "该设备不存在";
- }
- equipment.setIsBlocked(block);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 修改设备睡眠状态
- *
- * @param clientId
- * @param is_sleep
- * @return
- */
- @RequestMapping(value = "/updateSleep.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateSleep(String clientId, Boolean is_sleep) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- if(is_sleep!=null){
- equipment.setIsSleep(is_sleep);
- equipmentService.updateById(equipment);
- }
- return "修改成功";
- }
- /**
- * 修改设备生产棉花糖个数
- *
- * @param clientId
- * @param productTotal
- * @return
- */
- @RequestMapping(value = "/updateProductTotal.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateProductTotal(String clientId, Integer productTotal) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- Integer total = equipment.getProductTotal();
- if (total == null) {
- total = 0;
- }
- equipment.setProductTotal(total + productTotal);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 修改设备共同参数/进阶参数
- *
- * @param
- * @return
- */
- // @PostMapping(value = "/updateParam/{code}/{clientId}", produces = "application/json;charset=UTF-8")
- // @ResponseBody
- // public JsonMessage updateParam(@PathVariable Integer code, @PathVariable String clientId, @RequestBody List<CommonParamVo> commonParamVos) {
- // Equipment equipment = equipmentService.findByClientId(clientId);
- // if (equipment == null) {
- // return JsonMessage.error("设备不存在");
- // }
- // String param = JSONArray.toJSONString(commonParamVos);
- // if (code == 0) {
- // equipment.setCommonParameters(param);
- // } else {
- // equipment.setAdvancedParameters(param);
- // }
- // equipmentService.update(equipment);
- // return JsonMessage.success("修改成功");
- // }
- /**
- * 修改设备共同参数/进阶参数
- * code 0:通用参数;1:进阶参数;2:调试页参数;3:湿度参数
- * @param
- * @return
- */
- @RequestMapping(value = "/updateParamNew", method = RequestMethod.POST)
- @ResponseBody
- public String updateParamNew(Integer code, String clientId, @RequestBody List<CommonParamVo> commonParamVos) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "设备不存在";
- }
- if(commonParamVos.size()<=0){
- return "参数为空";
- }
- LambdaQueryWrapper<TParameters> queryParameters = Wrappers.lambdaQuery();
- queryParameters.eq(TParameters::getClientId,clientId);
- queryParameters.eq(TParameters::getStatus,code);
- queryParameters.eq(TParameters::getEquipmentId,equipment.getId());
- List<TParameters> list = parametersService.list(queryParameters);
- if(list.size()>0){
- for(TParameters parameters:list){
- //删除旧的参数
- parametersService.removeById(parameters.getId());
- }
- }
- Date date = new Date();
- for(CommonParamVo commonParamVo:commonParamVos){
- TParameters parameters = new TParameters();
- parameters.setVal(commonParamVo.getVal());
- parameters.setName(commonParamVo.getName());
- parameters.setStatus(String.valueOf(code));
- parameters.setClientId(clientId);
- parameters.setEquipmentId(equipment.getId());
- parameters.setCreateDate(date);
- parameters.setModifyDate(date);
- parametersService.save(parameters);
- }
- return "修改成功";
- }
- /**
- * 修改单个设备共同参数/进阶参数
- * code 0:通用参数;1:进阶参数;2:调试页参数;3:湿度参数
- * @param
- * @return
- */
- @PostMapping(value = "/updateAloneParam.htm", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateAloneParam(String code, String clientId,String name,String val) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- // return JsonMessage.error("设备不存在");
- return "设备不存在";
- }
- // ArrayList<Filter> filters = new ArrayList<>();
- // filters.add(Filter.eq("status", code));
- // filters.add(Filter.eq("clientId", clientId));
- // filters.add(Filter.eq("equipmentId", equipment.getId()));
- // filters.add(Filter.eq("name", name));
- // List<Parameters> list = parametersService.findList(null, filters, null);
- LambdaQueryWrapper<TParameters> queryParameters = Wrappers.lambdaQuery();
- queryParameters.eq(TParameters::getClientId,clientId);
- queryParameters.eq(TParameters::getStatus,code);
- queryParameters.eq(TParameters::getName,name);
- queryParameters.eq(TParameters::getEquipmentId,equipment.getId());
- List<TParameters> list1 = parametersService.list(queryParameters);
- if(list1.size()>0){
- TParameters parameters = list1.get(0);
- parameters.setVal(val);
- parameters.setModifyDate(new Date());
- parametersService.updateById(parameters);
- }
- return "修改成功";
- }
- /**
- * 获取机器列表
- */
- @RequestMapping(value = "/getEquipmentList.htm", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
- @ResponseBody
- public String getByAdminAndProduct(String adminId,String name) {
- JSONObject jsonObject = new JSONObject();
- if(StringUtils.isEmpty(adminId)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "adminId为空");
- return jsonObject.toJSONString();
- }
- if(StringUtils.isEmpty(name)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "name为空");
- return jsonObject.toJSONString();
- }
- // Admin admin = adminService.find(Long.valueOf(adminId));
- TAdmin admin = adminService.getById(adminId);
- if(!admin.getUsername().equals(name)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "name与adminId不匹配");
- return jsonObject.toJSONString();
- }
- List<EquipmentDTO> list = new ArrayList<>();
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getAdminId,Long.valueOf(adminId));
- List<TEquipment> equipmentList = equipmentService.list(query);
- // List<TEquipment> equipmentList = equipmentService.findByAdminId(Long.valueOf(adminId));
- for(TEquipment equipment:equipmentList){
- EquipmentDTO equipmentDTO = new EquipmentDTO();
- equipmentDTO.setClientId(equipment.getClientId());
- equipmentDTO.setSn(equipment.getSn());
- equipmentDTO.setName(equipment.getName());
- equipmentDTO.setLatitude(equipment.getLatitude());
- equipmentDTO.setLongitude(equipment.getLongitude());
- equipmentDTO.setFullName(equipment.getFullName());
- equipmentDTO.setEqeStatus(equipment.getEqeStatus());
- list.add(equipmentDTO);
- }
- jsonObject.put("code", 0);
- jsonObject.put("rows", JsonUtils.toJson(list));
- jsonObject.put("errmsg", "");
- jsonObject.put("total", list.size());
- return jsonObject.toJSONString();
- }
- /**
- * 获取商品信息
- */
- @RequestMapping(value = "/getProductions.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getProductions(String adminId,String clientId) {
- JSONObject jsonObject = new JSONObject();
- if(StringUtils.isEmpty(adminId)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "adminId为空");
- return jsonObject.toJSONString();
- }
- if(StringUtils.isEmpty(clientId)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "clientId为空");
- return jsonObject.toJSONString();
- }
- // KafkaProperties.Admin admin = adminService.find(Long.valueOf(adminId));
- TAdmin admin = adminService.getById(Long.valueOf(adminId));
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- // Equipment equipment = equipmentService.findByClientId(clientId);
- if(!equipment.getAdminId().toString().equals(admin.getId().toString())){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "clientId与adminId不匹配");
- return jsonObject.toJSONString();
- }
- // ArrayList<Filter> filters = new ArrayList<>();
- // filters.add(Filter.eq("equipmentId", equipment.getId()));
- // List<Product> products = productService.findList(null, filters, null);
- List<String> list = new ArrayList<>();
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- List<TProduct> products = productService.list(queryProduct);
- // TProduct tProduct = products.get(0);
- for (TProduct product:products){
- list.add(product.getProductName());
- }
- jsonObject.put("code", 0);
- jsonObject.put("productions", JsonUtils.toJson(list));
- jsonObject.put("errmsg", "");
- jsonObject.put("total", list.size());
- return jsonObject.toJSONString();
- }
- /**
- * 根据设备编号获取商品信息
- */
- @RequestMapping(value = "/getproducts", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getproducts(String clientId) {
- JSONObject jsonObject = new JSONObject();
- if(StringUtils.isEmpty(clientId)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "clientId为空");
- return jsonObject.toJSONString();
- }
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- List<TProduct> products = productService.list(queryProduct);
- // TProduct tProduct = products.get(0);
- for (TProduct product:products){
- product.setCreateDate(null);
- product.setModifyDate(null);
- }
- // jsonObject.put("code", 0);
- // jsonObject.put("productions", JsonUtils.toJson(list));
- // jsonObject.put("errmsg", "");
- // jsonObject.put("total", list.size());
- // return jsonObject.toJSONString();
- JSONObject jsonObject1 = new JSONObject();
- jsonObject1.put("code", 0);
- jsonObject1.put("data", JSONObject.toJSON(products).toString());
- jsonObject1.put("errmsg", "");
- // return jsonObject1.toString();
- return JSONObject.toJSON(products).toString();
- }
- // @ApiOperation(value = "分页查询")
- // @GetMapping("/testPage")
- // public ResponseModel<IPage<?>> testPage(TAdminParam param) {
- // LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
- // query.eq(TAdmin::getIsEnabled,true);
- // if(StrUtil.isNotBlank(param.getName())){
- // query.like(TAdmin::getName,param.getName());
- // }
- // query.orderByDesc(TAdmin::getApplyStartTime);
- // Page<TAdmin> page = new Page<>(param.getCurrent(), param.getSize(), true);
- // IPage<TAdmin> iPage = tAdminService.page(page, query);
- // return R.ok(iPage);
- // }
- //
- // @ApiOperation(value = "列表查询")
- // @GetMapping("/testList")
- // public ResponseModel<List<?>> testList(TAdminParam param) {
- // LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
- // query.eq(TAdmin::getIsEnabled,true);
- // if(StrUtil.isNotBlank(param.getName())){
- // query.like(TAdmin::getName,param.getName());
- // }
- // query.orderByDesc(TAdmin::getApplyStartTime);
- // List<TAdmin> list = tAdminService.list(query);
- // return R.ok(list);
- // }
- // @ApiOperation(value = "返回失败")
- // @GetMapping("/testError")
- // public ResponseModel<List<?>> testError(boolean success) {
- // if(success){
- // return R.ok();
- // }else{
- // return R.fail(ResponseCodesEnum.B0001,"你的错误信息");
- // }
- // }
- /**
- *是否启用物料监控功能
- * 0:不启用,1:启用
- * @param clientId 个推
- * @return
- */
- @RequestMapping(value = "/updateMaterialStatus.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateMaterialUse(String clientId, String isMaterialUse){
- if(!StringUtils.isEmpty(clientId)&&!StringUtils.isEmpty(isMaterialUse)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- equipmentDesc.setIsMaterialUse(isMaterialUse);
- equipmentDescService.updateById(equipmentDesc);
- // 改变参数表里的状态
- LambdaQueryWrapper<TParameters> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(TParameters::getClientId,clientId);
- queryWrapper.eq(TParameters::getName,"M502");
- TParameters parameters = parametersService.getOne(queryWrapper);
- parameters.setVal(isMaterialUse);
- parametersService.updateById(parameters);
- return "success";
- }
- return "error";
- }
- //修改优惠码状态
- @RequestMapping(value = "/updateCode.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String CardPay(String code, String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- LambdaQueryWrapper<TPromoCode> query1 = Wrappers.lambdaQuery();
- query1.eq(TPromoCode::getAdminId,equipment.getAdminId());
- query1.eq(TPromoCode::getCode,code);
- List<TPromoCode> list1 = promoCodeService.list(query1);
- TPromoCode promoCode = list1.get(0);
- promoCode.setIsUse("1");
- promoCode.setUseBy(equipment.getName());
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String time = sdf.format(new Date());
- promoCode.setUseDate(time);
- promoCodeService.updateById(promoCode);
- return "success";
- }
- //验证优惠码
- @RequestMapping(value = "/selectCode.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String selectCode(String code, String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- //验证优惠码
- LambdaQueryWrapper<TPromoCode> query1 = Wrappers.lambdaQuery();
- query1.eq(TPromoCode::getCode,code);
- List<TPromoCode> codeList = promoCodeService.list(query1);
- TPromoCode promoCode = new TPromoCode();
- if (codeList.size() == 0) {
- //不存在
- // return JsonMessage.success("1");
- return "1";
- }
- for (TPromoCode cod : codeList) {
- if(!cod.getAdminId().equals("1")){
- String adminId = cod.getAdminId();
- String adminId1 = String.valueOf(equipment.getAdminId());
- if (adminId.equals(adminId1)) {
- promoCode = cod;
- }
- }else{
- promoCode = cod;
- }
- }
- if(promoCode.getAdminId()==null){
- //不是本机
- // return JsonMessage.success("3");
- return "3";
- }
- Date lastUseDate = null;
- if (promoCode != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- promoCodeService.updateById(promoCode);
- //过期
- // return JsonMessage.success("4");
- return "4";
- }
- if (promoCode.getId() == null) {
- //不存在
- // return JsonMessage.success("1");
- return "1";
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- // return JsonMessage.success("2");
- return "2";
- }
- if(!promoCode.getAdminId().equals("1")){
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- // return JsonMessage.success("3");
- return "3";
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- // return JsonMessage.success("0");
- return "0";
- }
- if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
- //0折
- // return JsonMessage.success("0");
- return "0";
- }
- // return JsonMessage.success("success");
- return "success";
- }
- //修改机器的分销
- @RequestMapping(value = "/updateProportion.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateProportion(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if(equipment!=null&&equipment.getId()!=null){
- TAdmin admin = adminService.getById(equipment.getAdminId());
- String name = admin.getName();
- //查询机器是否已经有设置分销
- LambdaQueryWrapper<TProportion> query1 = Wrappers.lambdaQuery();
- query1.eq(TProportion::getClientId,equipment.getClientId());
- query1.eq(TProportion::getEquipmentId,equipment.getId());
- List<TProportion> list1 = proportionService.list(query1);
- if(list1.size()>0){
- //已有
- }else {
- //没有,需要创建
- //1,判断是否新机器
- // Date createDate = equipment.getCreateDate();
- // long time = createDate.getTime();
- // DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- // String day= "2022-09-21 23:59:59";
- // try {
- // Date parse = simpleDateFormat.parse(day);
- // if(time>parse.getTime()){
- // return "新机器,不能已此方式生成分销!";
- // }
- // } catch (ParseException e) {
- // e.printStackTrace();
- // }
- //先找到原账户的分销
- LambdaQueryWrapper<TProportion> query2 = Wrappers.lambdaQuery();
- query2.eq(TProportion::getAdminId,admin.getId());
- List<TProportion> list2 = proportionService.list(query2);
- if(list2.size()>0){
- TProportion adminProportion = list2.get(0);
- if(StringUtils.isEmpty(adminProportion.getClientId())){
- TProportion equipmentProportion = new TProportion();
- equipmentProportion.setCreateDate(new Date());
- equipmentProportion.setModifyDate(new Date());
- equipmentProportion.setAdminId(admin.getId());
- equipmentProportion.setClientId(equipment.getClientId());
- equipmentProportion.setEquipmentId(equipment.getId());
- equipmentProportion.setAdminProportion(adminProportion.getAdminProportion());
- Integer type = adminProportion.getType();
- switch (type) {
- case 1:
- equipmentProportion.setProportion(adminProportion.getAgencyProportion());
- equipmentProportion.setAgencyProportion(new BigDecimal("0.00"));
- equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(0);
- break;
- case 2:
- equipmentProportion.setProportion(adminProportion.getMerchantProportion());
- equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
- // if(adminProportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))!=0){
- // equipmentProportion.setAgencyId(admin.getAgencyId());
- // TAdmin byId = adminService.getById(admin.getAgencyId());
- // equipmentProportion.setAgencyName(byId.getUsername());
- // }
- equipmentProportion.setAgencyId(admin.getAgencyId());
- TAdmin byId = adminService.getById(admin.getAgencyId());
- equipmentProportion.setAgencyName(byId.getUsername());
- equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(1);
- break;
- case 3:
- equipmentProportion.setProportion(adminProportion.getPersonageProportion());
- equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
- // if(adminProportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))!=0){
- // equipmentProportion.setAgencyId(admin.getAgencyId());
- // TAdmin byId = adminService.getById(admin.getAgencyId());
- // equipmentProportion.setAgencyName(byId.getUsername());
- // }
- equipmentProportion.setAgencyId(admin.getAgencyId());
- TAdmin byId1 = adminService.getById(admin.getAgencyId());
- equipmentProportion.setAgencyName(byId1.getUsername());
- equipmentProportion.setMerchantProportion(adminProportion.getMerchantProportion());
- // if(adminProportion.getMerchantProportion().compareTo(new BigDecimal("0.00"))!=0){
- // equipmentProportion.setMerchantId(admin.getMerchantId());
- // TAdmin byId = adminService.getById(admin.getMerchantId());
- // equipmentProportion.setMerchantName(byId.getUsername());
- // }
- equipmentProportion.setMerchantId(admin.getMerchantId());
- TAdmin byId2 = adminService.getById(admin.getMerchantId());
- equipmentProportion.setMerchantName(byId2.getUsername());
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(2);
- break;
- }
- boolean save = proportionService.save(equipmentProportion);
- }
- }else {
- return "原账户没有设置分销!";
- }
- }
- }
- return "success";
- }
- /**
- *
- *
- * @param clientId
- * @return
- */
- @GetMapping(value = "/getManagerId.htm")
- @ResponseBody
- public String getManagerId(String clientId){
- if(!StringUtils.isEmpty(clientId)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- if (list.size()>0) {
- TEquipment equipment = list.get(0);
- Long adminId = equipment.getAdminId();
- if(adminId!=null){
- String managerId = AdminUtils.encrypt(false, adminId);
- if(StringUtils.isEmpty(equipment.getManagerId())||!equipment.getManagerId().equals(managerId)){
- equipment.setManagerId(managerId);
- equipmentService.save(equipment);
- }
- return managerId;
- }
- }
- return "error";
- }
- return "error";
- }
- /**
- * 修改优惠券开关状态
- *
- * @param clientId
- * @return
- */
- @GetMapping(value = "/updateCouponStatus.htm")
- @ResponseBody
- public String updateCouponStatus(String clientId,String couponStatus){
- if(!StringUtils.isEmpty(clientId)&&StringUtils.isNotEmpty(couponStatus)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- equipmentDesc.setCouponStatus(couponStatus);
- equipmentDescService.updateById(equipmentDesc);
- TAdmin admin = adminService.getById(equipment.getAdminId());
- //同步数据到鲸准
- if(admin.getId().toString().equals("372")||admin.getRelationAdminId().equals("372")||admin.getId().toString().equals("639")||admin.getId().toString().equals("238")) {
- sendCouponStatus(clientId,equipment.getFullName(),equipment.getEqeStatus(),couponStatus);
- }
- return "success";
- }
- return "error";
- }
- private void sendCouponStatus(String clientId, String fullName, Integer eqeStatus, String couponStatus) {
- String url = "http://47.106.13.109:3000/api/listenDeviceStatusChange";
- Map<String,String> map = new HashMap<>();
- map.put("clientId",clientId);
- map.put("address",fullName);
- map.put("status", String.valueOf(eqeStatus));
- if(StringUtils.isEmpty(couponStatus)){
- map.put("wxStatus","1");
- }else {
- map.put("wxStatus",couponStatus);
- }
- String data = JSON.toJSONString(map);
- try {
- String s = HttpClientSslUtils.doPost(url, data);
- System.out.println("发送鲸准:"+s);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- *
- *
- * @param clientId
- * @return
- */
- @GetMapping(value = "/getYouHuiPrice.htm")
- @ResponseBody
- public String getYouHuiPrice(String clientId){
- LambdaQueryWrapper<TPrice> query = Wrappers.lambdaQuery();
- query.eq(TPrice::getName,"优惠券");
- List<TPrice> list = priceService.list(query);
- if(list.size()>0){
- TPrice tPrice = list.get(0);
- Double price = tPrice.getPrice();
- return new BigDecimal(price).setScale(0, RoundingMode.HALF_DOWN).toString();
- }else {
- return "5";
- }
- }
- /**
- * 修改商品名称
- *
- * @param clientId 设备个推Id
- * @param
- * @return
- * @Param
- */
- @RequestMapping(value = "/updateProductName.htm", method = RequestMethod.POST)
- @ResponseBody
- public String updateProductName(String clientId, Long productId,String oldProductName, String newProductName) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- if(list.size()>0){
- TEquipment equipment = list.get(0);
- if (equipment != null&&equipment.getId()!=null) {
- TProduct product = productService.getById(productId);
- product.setName(oldProductName);
- product.setProductName(newProductName);
- productService.updateById(product);
- return "修改成功success!";
- }
- }
- return "更新失败error";
- }
- /**
- * 上传机器状态之门的状态:
- * type(类型,0:外门,1:内门),
- * status(状态:0:关闭,1:开启)
- * @param clientId
- * @return status(状态:0:关闭,1:开启)
- */
- @GetMapping("/updateEquipmentStatus")
- public ResponseModel<?> updateEquipmentStatus(String clientId, String type, String status){
- if(StringUtils.isEmpty(clientId)||StringUtils.isEmpty(type)||StringUtils.isEmpty(status)){
- return R.fail(ResponseCodesEnum.A0001,"adminId为空");
- }
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOnly(query);
- if(equipment!=null&&equipment.getId()!=null){
- if(type.equals("0")){
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- equipmentDesc.setOutDoor(status);
- equipmentDescService.updateById(equipmentDesc);
- return R.ok();
- }else if(type.equals("1")){
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- equipmentDesc.setInDoor(status);
- equipmentDescService.updateById(equipmentDesc);
- return R.ok();
- }
- }
- return R.fail(ResponseCodesEnum.A0002);
- }
- /**
- * 上传花型显示状态
- * @param clientId 设备编号
- * @param tProductBean 包含花型编号和状态
- * @return
- */
- @RequestMapping(value = "/updateShowGoods", method = RequestMethod.POST)
- @ResponseBody
- public String updateShowGoods(@RequestParam String clientId, @RequestBody List<TProductBean> tProductBean) {
- if(StringUtils.isEmpty(clientId)||tProductBean == null) {
- return "参数为空";
- }
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOnly(query);
- if (equipment==null) {
- return "找不到设备信息";
- }
- Long equipmentId = equipment.getId();
- ArrayList<TProduct> tProducts = new ArrayList<>();
- for (TProductBean productBean : tProductBean) {
- String no = productBean.getNo();
- String showType = productBean.getShowType();
- LambdaQueryWrapper<TProduct> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(TProduct::getEquipmentId,equipmentId);
- wrapper.eq(TProduct::getNo,no);
- TProduct product = productService.getOnly(wrapper);
- product.setShowType(showType);
- tProducts.add(product);
- }
- boolean res = productService.updateBatchById(tProducts);
- if (!res) {
- return "error";
- }
- return "success";
- }
- /**
- * 修改机型
- * @param clientId
- * @param equipmentType
- * @return
- */
- @GetMapping(value = "/updateEquipmentType")
- @ResponseBody
- public String updateEquipmentType(String clientId,String equipmentType){
- if(StringUtils.isNotEmpty(clientId)&&StringUtils.isNotEmpty(equipmentType)){
- // 删除MQ队列
- amqpAdmin.deleteQueue(clientId);
- // 重新创建队列
- Map<String,Object> arg = new HashMap<>();
- arg.put("x-message-ttl",1800000);
- HashMap<String, Object> objectObjectHashMap = new HashMap<>();
- amqpAdmin.declareBinding(new Binding(clientId,
- Binding.DestinationType.QUEUE,
- equipmentType, clientId, objectObjectHashMap));
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- equipment.setEquimentType(equipmentType);
- equipmentService.updateById(equipment);
- return "success";
- }
- return "error";
- }
- }
|