| | |
| | | package com.stylefeng.guns.modular.system.controller.general; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | |
| | | import com.stylefeng.guns.core.util.DateUtil; |
| | | import com.stylefeng.guns.core.util.SinataUtil; |
| | | import com.stylefeng.guns.modular.system.model.SysRedPacketRecord; |
| | | import com.stylefeng.guns.modular.system.model.TRegion; |
| | | import com.stylefeng.guns.modular.system.service.ITRegionService; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | |
| | | import com.stylefeng.guns.modular.system.service.ISysCouponRecordService; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | |
| | | /** |
| | | * 控制器 |
| | |
| | | |
| | | @Autowired |
| | | private ISysCouponRecordService sysCouponRecordService; |
| | | |
| | | @Autowired |
| | | private ITRegionService tRegionService; |
| | | |
| | | /** |
| | | * 跳转到首页 |
| | |
| | | * 跳转到添加 |
| | | */ |
| | | @RequestMapping("/sysCouponRecord_add") |
| | | public String sysCouponRecordAdd() { |
| | | public String sysCouponRecordAdd(Model model) { |
| | | List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0)); |
| | | model.addAttribute("provinceList",provinceList); |
| | | return PREFIX + "sysCouponRecord_add.html"; |
| | | } |
| | | |
| | |
| | | SysCouponRecord sysCouponRecord = sysCouponRecordService.selectById(sysCouponRecordId); |
| | | model.addAttribute("item",sysCouponRecord); |
| | | LogObjectHolder.me().set(sysCouponRecord); |
| | | List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0)); |
| | | model.addAttribute("provinceList",provinceList); |
| | | return PREFIX + "sysCouponRecord_edit.html"; |
| | | } |
| | | |
| | |
| | | sysCouponRecord.setInsertTime(new Date()); |
| | | sysCouponRecord.setCompanyId(ShiroKit.getUser().getObjectId()); |
| | | sysCouponRecord.setCompanyType(ShiroKit.getUser().getRoleType()); |
| | | String citys = sysCouponRecord.getCitys(); |
| | | JSONArray jsonArray = JSON.parseArray(citys); |
| | | JSONArray citys_list = new JSONArray(); |
| | | List<TRegion> tRegions = tRegionService.selectList(null); |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | Integer integer = jsonArray.getInteger(i); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("code", integer); |
| | | Optional<TRegion> first = tRegions.stream().filter(s->s.getCode().equals(integer.toString())).findFirst(); |
| | | if(first.isPresent()){ |
| | | TRegion tRegion = first.get(); |
| | | jsonObject.put("name", tRegion.getName()); |
| | | } |
| | | citys_list.add(jsonObject); |
| | | } |
| | | sysCouponRecord.setCitys(citys_list.toString()); |
| | | sysCouponRecordService.insert(sysCouponRecord); |
| | | return SUCCESS_TIP; |
| | | } |
| | |
| | | @RequestMapping(value = "/update") |
| | | @ResponseBody |
| | | public Object update(SysCouponRecord sysCouponRecord) { |
| | | String citys = sysCouponRecord.getCitys(); |
| | | JSONArray jsonArray = JSON.parseArray(citys); |
| | | JSONArray citys_list = new JSONArray(); |
| | | List<TRegion> tRegions = tRegionService.selectList(null); |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | Integer integer = jsonArray.getInteger(i); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("code", integer); |
| | | Optional<TRegion> first = tRegions.stream().filter(s->s.getCode().equals(integer.toString())).findFirst(); |
| | | if(first.isPresent()){ |
| | | TRegion tRegion = first.get(); |
| | | jsonObject.put("name", tRegion.getName()); |
| | | } |
| | | citys_list.add(jsonObject); |
| | | } |
| | | sysCouponRecord.setCitys(citys_list.toString()); |
| | | sysCouponRecordService.updateById(sysCouponRecord); |
| | | return SUCCESS_TIP; |
| | | } |