师傅圈后台接口开发

This commit is contained in:
donqi 2022-06-25 17:32:05 +08:00
parent 763607b657
commit 6a92f40b51
15 changed files with 253 additions and 4 deletions

View File

@ -1,23 +1,35 @@
package com.ghy.web.controller.worker;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.page.TableDataInfo;
import com.ghy.common.enums.GoodsStatus;
import com.ghy.common.enums.WorkerStatus;
import com.ghy.common.utils.ExceptionUtil;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.service.GoodsService;
import com.ghy.web.pojo.vo.WorkerListRequest;
import com.ghy.web.pojo.vo.WorkerListResponse;
import com.ghy.web.pojo.vo.WorkerSettledRequest;
import com.ghy.worker.domain.Worker;
import com.ghy.worker.domain.WorkerArea;
import com.ghy.worker.domain.WorkerGoodsCategory;
import com.ghy.worker.service.WorkerAreaService;
import com.ghy.worker.service.WorkerGoodsCategoryService;
import com.ghy.worker.service.WorkerService;
import com.ghy.worker.service.WorkerSpecialSkillService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author clunt
@ -41,20 +53,58 @@ public class WorkerController extends BaseController {
@Autowired
private WorkerSpecialSkillService specialSkillService;
@Autowired
private GoodsService goodsService;
@RequiresPermissions("worker:worker:view")
@GetMapping()
public String worker(){
return prefix + "/worker";
}
@RequiresPermissions("worker:worker:list")
// @RequiresPermissions("worker:worker:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(Worker worker)
public TableDataInfo list(@RequestBody WorkerListRequest workerListRequest)
{
List<WorkerListResponse> resList = new ArrayList<WorkerListResponse>();
// 查询满足区域条件的师傅区域记录
WorkerArea workerArea = new WorkerArea();
workerArea.setDistrictId(workerListRequest.getAreaId());
List<WorkerArea> workerAreaList = workerAreaService.getWorkerAreaList(workerArea);
List<Long> workerIdsByArea = workerAreaList.stream().map(WorkerArea::getWorkerId).collect(Collectors.toList());
// 查询满足技能条件的师傅技能记录
WorkerGoodsCategory workerGoodsCategory = new WorkerGoodsCategory();
workerGoodsCategory.setGoodsCategoryId(workerListRequest.getGoodsCategoryId());
List<WorkerGoodsCategory> workerGoodsCategoryList = workerGoodsCategoryService.getWorkerGoodsCategory(workerGoodsCategory);
List<Long> workerIdsByCategory = workerGoodsCategoryList.stream().map(WorkerGoodsCategory::getWorkerId).collect(Collectors.toList());
// 两个list中的workerid取交集
List<Long> resWorkerIds = new ArrayList<>(CollectionUtils.intersection(workerIdsByArea, workerIdsByCategory));
if (CollectionUtils.isEmpty(resWorkerIds)) {
// 交集不存在的情况直接返回空list
return getDataTable(resList);
}
startPage();
Worker worker = new Worker();
worker.setWorkerIds(CollectionUtils.isNotEmpty(resWorkerIds) ? resWorkerIds : null);
worker.setName(workerListRequest.getWorkerName());
List<Worker> list = workerService.getWorkList(worker);
return getDataTable(list);
list.forEach(w -> {
Goods goods = new Goods();
goods.setWorkerId(w.getWorkerId());
goods.setStatus(Integer.valueOf(GoodsStatus.OK.getCode()));
WorkerListResponse workerListResponse = JSONObject.parseObject(JSON.toJSONString(w), WorkerListResponse.class);
workerListResponse.setGoodsList(goodsService.selectGoodsList(goods));
workerListResponse.setWorkerAreas(workerAreaService.getByWorker(w.getWorkerId()));
workerListResponse.setGoodsCategories(workerGoodsCategoryService.getByWorker(w.getWorkerId()));
workerListResponse.setSpecialSkills(specialSkillService.getByWorker(w.getWorkerId()));
resList.add(workerListResponse);
});
return getDataTable(resList);
}
@PostMapping("/update")

View File

@ -0,0 +1,103 @@
//package com.ghy.web.core;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.ghy.common.utils.StringUtils;
//import net.sourceforge.pinyin4j.PinyinHelper;
//import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
//import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
//
//import java.io.*;
//import java.util.ArrayList;
//import java.util.List;
//
//import static net.sourceforge.pinyin4j.format.HanyuPinyinToneType.WITHOUT_TONE;
//import static net.sourceforge.pinyin4j.format.HanyuPinyinVCharType.WITH_U_UNICODE;
//
///**
// * @author ydq
// * @date : 2022-06-23 10:56
// */
//public class Trans {
//
// public static void main(String[] args) throws IOException, BadHanyuPinyinOutputFormatCombination {
// String json = readFile2String("/Users/ydq/Downloads/Administrative-divisions-of-China-master/dist/pcas-code.json");
// JSONArray jsonArray = JSON.parseArray(json);
// HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
// format.setVCharType(WITH_U_UNICODE);
// format.setToneType(WITHOUT_TONE);
// List<String> sqlList = getChildSqls(jsonArray, 1, null, "", format);
// writeLine2File("/Users/ydq/Documents/extraProject/dingdong/sysArea.sql", sqlList);
// }
//
// public static String readFile2String(String filePath) {
// StringBuilder strBuilder = new StringBuilder();
// File ioFile = new File(filePath);
// try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(ioFile), "UTF-8");
// BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
// String line;
// while ((line = bufferedReader.readLine()) != null) {
// strBuilder.append(line);
// }
// } catch (UnsupportedEncodingException unsupportedEncodingException) {
// unsupportedEncodingException.printStackTrace();
// } catch (FileNotFoundException fileNotFoundException) {
// fileNotFoundException.printStackTrace();
// } catch (IOException ioException) {
// ioException.printStackTrace();
// }
// return strBuilder.toString();
// }
//
// public static void writeLine2File(String filePath, List<String> lines) throws IOException {
// File ioFile = new File(filePath);
//
// try (
// OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(ioFile), "UTF-8");
// BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter); // = FileWriter默认utf-8
// ){
// for (String line: lines) {
// bufferedWriter.write(line);
// bufferedWriter.newLine();
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// public static List<String> getChildSqls(JSONArray jsonArray, int levelType, String parentCode, String preMergeName, HanyuPinyinOutputFormat format) throws BadHanyuPinyinOutputFormatCombination {
// List<String> lineList = new ArrayList<String>();
// for (Object obj: jsonArray) {
// StringBuilder sql = new StringBuilder();
// sql.append("INSERT INTO `sys_area` (`area_id`, `area_code`, `area_name`, `parent_code`, `merger_name`, `short_name`, `merger_short_name`, `level_type`, `pinyin`, `first_char`) VALUES (");
// JSONObject jObj = (JSONObject) obj;
// String name = jObj.getString("name");
// String code = jObj.getString("code");
// String pinyin = PinyinHelper.toHanYuPinyinString(name, format, "", false);
// String mergeName = StringUtils.isEmpty(preMergeName) ? name : preMergeName + "," + name;
// if (parentCode == null) {
// parentCode = "1";
// }
// sql.append(code).append(",")
// .append("'").append(code).append("'").append(",")
// .append("'").append(name).append("'").append(",")
// .append("'").append(parentCode).append("'").append(",")
// .append("'").append(mergeName).append("'").append(",")
// .append("'").append(name).append("'").append(",")
// .append("'").append(name).append("'").append(",")
// .append(levelType).append(",")
// .append("'").append(pinyin).append("'").append(",")
// .append("'").append(pinyin.charAt(0)).append("'")
// .append(");");
// System.out.println(sql.toString());
// lineList.add(sql.toString());
//
// if (jObj.getJSONArray("children") != null) {
// lineList.addAll(getChildSqls(jObj.getJSONArray("children"), levelType + 1, code, mergeName, format));
// }
// }
// return lineList;
// }
//
//}

View File

@ -0,0 +1,17 @@
package com.ghy.web.pojo.vo;
import com.ghy.worker.domain.Worker;
import lombok.Data;
/**
* @author ydq
* @date : 2022-06-24 17:38
*/
@Data
public class WorkerListRequest {
private Long areaId;
private Long goodsCategoryId;
private String workerName;
}

View File

@ -0,0 +1,28 @@
package com.ghy.web.pojo.vo;
import com.ghy.goods.domain.Goods;
import com.ghy.worker.domain.Worker;
import com.ghy.worker.domain.WorkerArea;
import com.ghy.worker.domain.WorkerGoodsCategory;
import com.ghy.worker.domain.WorkerSpecialSkill;
import lombok.Data;
import java.util.List;
/**
* @author ydq
* @date : 2022-06-24 17:14
*/
@Data
public class WorkerListResponse extends Worker {
private List<Goods> goodsList;
// 入驻区域
private List<WorkerArea> workerAreas;
// 服务品类
private List<WorkerGoodsCategory> goodsCategories;
// 特殊技能
private List<WorkerSpecialSkill> specialSkills;
}

View File

@ -103,6 +103,9 @@
<if test="status != null">
AND status = #{status}
</if>
<if test="workerId != null">
AND worker_id = #{workerId}
</if>
</where>
/* 默认生成时间排序 */
order by create_time

View File

@ -4,6 +4,8 @@ import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
import java.util.List;
/**
* @author clunt
* 师傅实体
@ -52,4 +54,5 @@ public class Worker extends BaseEntity {
@Excel(name = "领导团队扣费金额", cellType = Excel.ColumnType.STRING)
private String leaderTeamMoney;
private List<Long> workerIds;
}

View File

@ -21,4 +21,6 @@ public interface WorkerAreaMapper {
int deleteByWorker(Long workerId);
List<WorkerArea> getByWorker(Long workerId);
List<WorkerArea> getWorkerAreaList(WorkerArea workerArea);
}

View File

@ -21,4 +21,6 @@ public interface WorkerGoodsCategoryMapper {
int deleteByWorker(Long workerId);
List<WorkerGoodsCategory> getByWorker(Long workerId);
List<WorkerGoodsCategory> getWorkerGoodsCategory(WorkerGoodsCategory workerGoodsCategory);
}

View File

@ -20,4 +20,6 @@ public interface WorkerAreaService {
List<WorkerArea> getByWorker(Long workerId);
void updateWorkerServArea(Long workerId, List<WorkerArea> areas);
List<WorkerArea> getWorkerAreaList(WorkerArea area);
}

View File

@ -20,4 +20,6 @@ public interface WorkerGoodsCategoryService {
List<WorkerGoodsCategory> getByWorker(Long workerId);
void updateWorkerGoodsCategory(Long workerId, List<WorkerGoodsCategory> categories);
List<WorkerGoodsCategory> getWorkerGoodsCategory(WorkerGoodsCategory workerGoodsCategory);
}

View File

@ -59,4 +59,9 @@ public class WorkerAreaServiceImpl implements WorkerAreaService {
workerAreaMapper.delete(id2DelList.toArray(id2Del));
}
}
@Override
public List<WorkerArea> getWorkerAreaList(WorkerArea area) {
return workerAreaMapper.getWorkerAreaList(area);
}
}

View File

@ -67,4 +67,9 @@ public class WorkerGoodsCategoryServiceImpl implements WorkerGoodsCategoryServic
workerGoodsCategoryMapper.delete(id2DelList.toArray(id2Del));
}
}
@Override
public List<WorkerGoodsCategory> getWorkerGoodsCategory(WorkerGoodsCategory workerGoodsCategory) {
return workerGoodsCategoryMapper.getWorkerGoodsCategory(workerGoodsCategory);
}
}

View File

@ -60,6 +60,15 @@
WHERE wa.worker_id = #{workerId}
</select>
<select id="getWorkerAreaList" parameterType="com.ghy.worker.domain.WorkerArea" resultMap="WorkerAreaResult">
<include refid="selectWorkerArea"></include>
<where>
<if test="districtId != null">
AND district_id = #{districtId}
</if>
</where>
</select>
<delete id="deleteByWorker" parameterType="Long">
DELETE FROM worker_area WHERE worker_id = #{workerId}
</delete>

View File

@ -50,6 +50,15 @@
WHERE wgc.worker_id = #{workerId}
</select>
<select id="getWorkerGoodsCategory" parameterType="com.ghy.worker.domain.WorkerGoodsCategory" resultMap="WorkerGoodsCategoryResult">
<include refid="selectWorkerGoodsCategory"></include>
<where>
<if test="goodsCategoryId != null">
AND wgc.goods_category_id = #{goodsCategoryId}
</if>
</where>
</select>
<delete id="deleteByWorker" parameterType="Long">
DELETE FROM worker_goods_category WHERE worker_id = #{workerId}
</delete>

View File

@ -31,12 +31,21 @@
LEFT JOIN sys_dept sd ON w.dept_id = sd.dept_id
</sql>
<select id="getWorkerList" resultMap="WorkerResult">
<select id="getWorkerList" parameterType="com.ghy.worker.domain.Worker" resultMap="WorkerResult">
<include refid="selectWorker" />
<where>
<if test="openId != null and openId != ''">
AND open_id = #{openId}
</if>
<if test="workerIds != null and workerIds != ''">
AND w.worker_id IN
<foreach item="item" collection="workerIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="name != null and name != ''">
AND w.name LIKE '%${name}%'
</if>
</where>
</select>