汪菘
3 years ago
9 changed files with 446 additions and 15 deletions
@ -0,0 +1,87 @@ |
|||||
|
|
||||
|
package org.nl.acs.order.rest; |
||||
|
|
||||
|
|
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.acs.order.service.LabelingTemplateService; |
||||
|
import org.nl.acs.order.service.dto.LabelingTemplateDto; |
||||
|
import org.nl.annotation.Log; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.http.HttpStatus; |
||||
|
import org.springframework.http.ResponseEntity; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.IOException; |
||||
|
import java.sql.SQLException; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @author loujf |
||||
|
* @date 2022-06-01 |
||||
|
**/ |
||||
|
@RestController |
||||
|
@RequiredArgsConstructor |
||||
|
@Api(tags = "贴标模板管理") |
||||
|
@RequestMapping("/api/labelingTemplate") |
||||
|
@Slf4j |
||||
|
public class LabelingTemplateController { |
||||
|
|
||||
|
private final LabelingTemplateService labelingTemplateService; |
||||
|
|
||||
|
@GetMapping |
||||
|
@Log("查询贴标模板") |
||||
|
@ApiOperation("查询贴标模板") |
||||
|
//@PreAuthorize("@el.check('labelingTemplate:list')")
|
||||
|
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page){ |
||||
|
return new ResponseEntity<>(labelingTemplateService.queryAll(whereJson,page),HttpStatus.OK); |
||||
|
} |
||||
|
|
||||
|
@PostMapping |
||||
|
@Log("新增贴标模板") |
||||
|
@ApiOperation("新增贴标模板") |
||||
|
//@PreAuthorize("@el.check('labelingTemplate:add')")
|
||||
|
public ResponseEntity<Object> create(@Validated @RequestBody LabelingTemplateDto dto){ |
||||
|
labelingTemplateService.create(dto); |
||||
|
return new ResponseEntity<>(HttpStatus.CREATED); |
||||
|
} |
||||
|
|
||||
|
@PutMapping |
||||
|
@Log("修改贴标模板") |
||||
|
@ApiOperation("修改贴标模板") |
||||
|
//@PreAuthorize("@el.check('labelingTemplate:edit')")
|
||||
|
public ResponseEntity<Object> update(@Validated @RequestBody LabelingTemplateDto dto){ |
||||
|
labelingTemplateService.update(dto); |
||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT); |
||||
|
} |
||||
|
|
||||
|
@Log("删除贴标模板") |
||||
|
@ApiOperation("删除贴标模板") |
||||
|
//@PreAuthorize("@el.check('labelingTemplate:del')")
|
||||
|
@DeleteMapping |
||||
|
public ResponseEntity<Object> delete(@RequestBody String[] ids) { |
||||
|
labelingTemplateService.deleteAll(ids); |
||||
|
return new ResponseEntity<>(HttpStatus.OK); |
||||
|
} |
||||
|
|
||||
|
@Log("导出贴标模板") |
||||
|
@ApiOperation("导出贴标模板") |
||||
|
@GetMapping(value = "/download") |
||||
|
//@PreAuthorize("@el.check('labelingTemplate:list')")
|
||||
|
public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { |
||||
|
labelingTemplateService.download(labelingTemplateService.queryAll(whereJson), response); |
||||
|
} |
||||
|
|
||||
|
@PutMapping("/enabled") |
||||
|
@Log("启用禁用路由路线") |
||||
|
@ApiOperation("启用禁用路由路线") |
||||
|
//@PreAuthorize("@el.check('routeLine:edit')")
|
||||
|
public ResponseEntity<Object> enabled(@Validated @RequestBody LabelingTemplateDto dto) throws SQLException { |
||||
|
labelingTemplateService.enabled(dto.getTemplate_id(), dto.getIs_used()); |
||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT); |
||||
|
} |
||||
|
} |
@ -0,0 +1,82 @@ |
|||||
|
|
||||
|
package org.nl.acs.order.service; |
||||
|
|
||||
|
import org.nl.acs.order.service.dto.LabelingTemplateDto; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.IOException; |
||||
|
import java.sql.SQLException; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @description 服务接口 |
||||
|
* @author loujf |
||||
|
* @date 2022-06-01 |
||||
|
**/ |
||||
|
public interface LabelingTemplateService { |
||||
|
|
||||
|
/** |
||||
|
* 查询数据分页 |
||||
|
* @param whereJson 条件 |
||||
|
* @param page 分页参数 |
||||
|
* @return Map<String,Object> |
||||
|
*/ |
||||
|
Map<String,Object> queryAll(Map whereJson, Pageable page); |
||||
|
|
||||
|
/** |
||||
|
* 查询所有数据不分页 |
||||
|
* @param whereJson 条件参数 |
||||
|
* @return List<LabelingTemplateDto> |
||||
|
*/ |
||||
|
List<LabelingTemplateDto> queryAll(Map whereJson); |
||||
|
|
||||
|
/** |
||||
|
* 根据ID查询 |
||||
|
* @param template_id ID |
||||
|
* @return LabelingTemplate |
||||
|
*/ |
||||
|
LabelingTemplateDto findById(String template_id); |
||||
|
|
||||
|
/** |
||||
|
* 根据编码查询 |
||||
|
* @param code code |
||||
|
* @return LabelingTemplate |
||||
|
*/ |
||||
|
LabelingTemplateDto findByCode(String code); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 创建 |
||||
|
* @param dto / |
||||
|
*/ |
||||
|
void create(LabelingTemplateDto dto); |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
* @param dto / |
||||
|
*/ |
||||
|
void update(LabelingTemplateDto dto); |
||||
|
|
||||
|
/** |
||||
|
* 多选删除 |
||||
|
* @param ids / |
||||
|
*/ |
||||
|
void deleteAll(String[] ids); |
||||
|
|
||||
|
/** |
||||
|
* 导出数据 |
||||
|
* @param dtos 待导出的数据 |
||||
|
* @param response / |
||||
|
* @throws IOException / |
||||
|
*/ |
||||
|
void download(List<LabelingTemplateDto> dtos, HttpServletResponse response) throws IOException; |
||||
|
|
||||
|
/** |
||||
|
* 启用或停用 |
||||
|
* |
||||
|
* @param is_used 1 启用,0 禁用 |
||||
|
*/ |
||||
|
void enabled(String template_id, String is_used) throws SQLException; |
||||
|
} |
@ -0,0 +1,46 @@ |
|||||
|
package org.nl.acs.order.service.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @description / |
||||
|
* @author loujf |
||||
|
* @date 2022-06-01 |
||||
|
**/ |
||||
|
@Data |
||||
|
public class LabelingTemplateDto implements Serializable { |
||||
|
|
||||
|
/** 模板标识 */ |
||||
|
private String template_id; |
||||
|
|
||||
|
/** 模板编码 */ |
||||
|
private String template_code; |
||||
|
|
||||
|
/** 模板名称 */ |
||||
|
private String template_name; |
||||
|
|
||||
|
/** 模板地址 */ |
||||
|
private String template_address; |
||||
|
|
||||
|
/** 创建者 */ |
||||
|
private String create_by; |
||||
|
|
||||
|
/** 创建时间 */ |
||||
|
private String create_time; |
||||
|
|
||||
|
/** 修改者 */ |
||||
|
private String update_by; |
||||
|
|
||||
|
/** 修改时间 */ |
||||
|
private String update_time; |
||||
|
|
||||
|
/** 启用时间 */ |
||||
|
private String is_used_time; |
||||
|
|
||||
|
/** 是否启用 1-启用 0-禁用 */ |
||||
|
private String is_used; |
||||
|
|
||||
|
/** 是否删除 */ |
||||
|
private String is_delete; |
||||
|
} |
@ -0,0 +1,156 @@ |
|||||
|
|
||||
|
package org.nl.acs.order.service.impl; |
||||
|
|
||||
|
|
||||
|
import cn.hutool.core.date.DateUtil; |
||||
|
import cn.hutool.core.util.IdUtil; |
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.acs.order.service.LabelingTemplateService; |
||||
|
import org.nl.acs.order.service.dto.LabelingTemplateDto; |
||||
|
import org.nl.exception.BadRequestException; |
||||
|
import org.nl.utils.FileUtil; |
||||
|
import org.nl.utils.SecurityUtils; |
||||
|
import org.nl.wql.WQL; |
||||
|
import org.nl.wql.core.bean.WQLObject; |
||||
|
import org.nl.wql.util.WqlUtil; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.IOException; |
||||
|
import java.sql.SQLException; |
||||
|
import java.util.*; |
||||
|
|
||||
|
/** |
||||
|
* @description 服务实现 |
||||
|
* @author loujf |
||||
|
* @date 2022-06-01 |
||||
|
**/ |
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
@Slf4j |
||||
|
public class LabelingTemplateServiceImpl implements LabelingTemplateService { |
||||
|
|
||||
|
@Override |
||||
|
public Map<String,Object> queryAll(Map whereJson, Pageable page){ |
||||
|
HashMap<String, String> map = new HashMap<>(); |
||||
|
map.put("flag", "2"); |
||||
|
String template_code = (String) whereJson.get("template_code"); |
||||
|
String template_address = (String) whereJson.get("template_address"); |
||||
|
if (!StrUtil.isEmpty(template_code)) { |
||||
|
map.put("template_code", template_code); |
||||
|
} |
||||
|
if (!StrUtil.isEmpty(template_address)) { |
||||
|
map.put("template_address", template_address); |
||||
|
} |
||||
|
JSONObject jo = WQL.getWO("QPRODUCESHIFTORDER").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "update_time desc"); |
||||
|
return jo; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<LabelingTemplateDto> queryAll(Map whereJson){ |
||||
|
WQLObject wo = WQLObject.getWQLObject("acs_labeling_template"); |
||||
|
JSONArray arr = wo.query().getResultJSONArray(0); |
||||
|
List<LabelingTemplateDto> list = arr.toJavaList(LabelingTemplateDto.class); |
||||
|
return list; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public LabelingTemplateDto findById(String template_id) { |
||||
|
WQLObject wo = WQLObject.getWQLObject("acs_labeling_template"); |
||||
|
JSONObject json = wo.query("template_id ='" + template_id + "'").uniqueResult(0); |
||||
|
final LabelingTemplateDto obj = (LabelingTemplateDto) JSONObject.toJavaObject(json, LabelingTemplateDto.class); |
||||
|
return obj; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public LabelingTemplateDto findByCode(String code) { |
||||
|
WQLObject wo = WQLObject.getWQLObject("acs_labeling_template"); |
||||
|
JSONObject json = wo.query("template_code ='" + code + "'").uniqueResult(0); |
||||
|
final LabelingTemplateDto obj = (LabelingTemplateDto) JSONObject.toJavaObject(json, LabelingTemplateDto.class); |
||||
|
return obj; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void create(LabelingTemplateDto dto) { |
||||
|
String template_code = dto.getTemplate_code(); |
||||
|
LabelingTemplateDto templateDto = this.findByCode(template_code); |
||||
|
if (templateDto != null && templateDto.getIs_delete().equals("0")) { |
||||
|
throw new BadRequestException("存在相同的设备编码"); |
||||
|
} |
||||
|
|
||||
|
String currentUsername = SecurityUtils.getCurrentUsername(); |
||||
|
String now = DateUtil.now(); |
||||
|
|
||||
|
dto.setTemplate_id(IdUtil.simpleUUID()); |
||||
|
dto.setCreate_by(currentUsername); |
||||
|
dto.setUpdate_by(currentUsername); |
||||
|
dto.setUpdate_time(now); |
||||
|
dto.setCreate_time(now); |
||||
|
dto.setIs_used("1"); |
||||
|
|
||||
|
WQLObject wo = WQLObject.getWQLObject("acs_labeling_template"); |
||||
|
JSONObject json= (JSONObject) JSONObject.toJSON(dto); |
||||
|
wo.insert(json); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void update(LabelingTemplateDto dto) { |
||||
|
LabelingTemplateDto entity = this.findById(dto.getTemplate_id()); |
||||
|
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); |
||||
|
|
||||
|
String currentUsername = SecurityUtils.getCurrentUsername(); |
||||
|
String now = DateUtil.now(); |
||||
|
dto.setUpdate_time(now); |
||||
|
dto.setUpdate_by(currentUsername); |
||||
|
|
||||
|
WQLObject wo = WQLObject.getWQLObject("acs_labeling_template"); |
||||
|
JSONObject json= (JSONObject) JSONObject.toJSON(dto); |
||||
|
wo.update(json); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void deleteAll(String[] ids) { |
||||
|
WQLObject wo = WQLObject.getWQLObject("acs_labeling_template"); |
||||
|
for (String template_id: ids) { |
||||
|
wo.delete("template_id = '" + template_id + "'"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void download(List<LabelingTemplateDto> all, HttpServletResponse response) throws IOException { |
||||
|
List<Map<String, Object>> list = new ArrayList<>(); |
||||
|
for (LabelingTemplateDto labelingTemplate : all) { |
||||
|
Map<String,Object> map = new LinkedHashMap<>(); |
||||
|
map.put("模板编码", labelingTemplate.getTemplate_code()); |
||||
|
map.put("模板名称 ", labelingTemplate.getTemplate_name()); |
||||
|
map.put("模板地址", labelingTemplate.getTemplate_address()); |
||||
|
map.put("创建者", labelingTemplate.getCreate_by()); |
||||
|
map.put("创建时间", labelingTemplate.getCreate_time()); |
||||
|
map.put("修改者", labelingTemplate.getUpdate_by()); |
||||
|
map.put("修改时间", labelingTemplate.getUpdate_time()); |
||||
|
map.put("启用时间", labelingTemplate.getIs_used_time()); |
||||
|
map.put("是否启用", labelingTemplate.getIs_used()); |
||||
|
map.put("是否删除", labelingTemplate.getIs_delete()); |
||||
|
list.add(map); |
||||
|
} |
||||
|
FileUtil.downloadExcel(list, response); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void enabled(String template_id, String is_used) throws SQLException { |
||||
|
//贴标精度表
|
||||
|
WQLObject.getWQLObject("acs_labeling_template"); |
||||
|
LabelingTemplateDto dto = this.findById(template_id); |
||||
|
dto.setIs_used(is_used); |
||||
|
this.update(dto); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue